How to do something like switch case?

  • The available instructions will depend on the Fanuc software version that you are using.


    There is a SELECT instruction (at least on version 9.1). Its in the IF screen when adding an instruction. But that uses a Register value as the condition. I don't know if that will work for you.


    You can also do a similar behavior using JMP and LBL.


    IF cond1 is NOT true THEN JMP LBL100

    action 1

    JMP LBL 900

    LBL100

    IF cond2 is NOT true THEN JMP LBL 200

    action 2

    JMP LBL 900

    LBL200

    action 3 (else or default case goes here)

    JMP LBL 900


    LBL 900

  • The cleanest way is it use Select ...call. Then put your motions in different sub programs. Breaking up your program into smaller pieces is a good general programming practice anyway.


    Select R[x]=1 call sub1

    R[x] = 2, call sub2

    R[x] =3, call sub3

    ...

    Else, call subN

Advertising from our partners