When I have a simple while loop, how can I break out of it? (e.g. break in C/C++).
p
When I have a simple while loop, how can I break out of it? (e.g. break in C/C++).
p
You break out of while when the conditions on top are not met
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.
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.
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
Ah thanks guys for all the possible solutions!
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