RobotStudio event

How to break out of WHILE ?

Options
When I have a simple while loop, how can I break out of it? (e.g. break in C/C++).

p
Tagged:

Comments

  • pavpav
    Options
    You break out of while when the conditions on top are not met
  • pollux
    Options
    Hi pavpav, 

    Thanks I thought so but will hoping RAPID supported a C-ish `break`.  But if that's not possible I'll add it to the while condition.

    p.
  • Henrik Berlin
    Options
    The closest I can think of is the RETURN statement that will exit the current routine. That might work if you put your WHILE statement in a dedicated routine.
    Henrik Berlin
    ABB
  • DanLars
    Options
    Hey Pollux,

    You can also use the GOTO statement like this:

    MODULE WhileLoop
        VAR num count := 0;
        
        PROC TestWhileloop()

            WHILE TRUE DO
                
                IF count > 5 THEN
                    GOTO nextPart;
                ENDIF
                Incr count;
            ENDWHILE
            nextPart:
            TPWrite "Out of while loop";
            Stop;
        ENDPROC
        
    ENDMODULE

    hope it helps,

    Lars
    Lars Glud
    Danrob A/S
  • pollux
    Options
    Ah thanks guys for all the possible solutions!
  • AlexK
    AlexK ✭✭
    edited November 2014
    Options

    But then this would do the same with less code and without the use of GOTO which I ware thought never to use when I started programming ABB robots.


    MODULE WhileLoop
        VAR num count := 0;
        
        PROC TestWhileloop()

            WHILE count <= 5 DO
                Incr count;
            ENDWHILE

            TPWrite "Out of while loop";
            Stop;
        ENDPROC
        
    ENDMODULE

    Best regards
    Alexander Källberg