HOME ➔ SUPPORT ➔ Community ➔ General CourseLab issues ... exit a for-loop
exit a for-loop
  View type:
Hi all!

Is there anybody who knows how to exit a for-loop BEFORE the TO-statement has reached? Something like:

For (From=1, To=10, Step=1)
if something >= 50
exit

Thanks for each answer!
 
Hi, mamonga,

At least you can leave FOR cycle with CALL and GOTO actions (which transfers you to selected slide or frame). Not sure (cannot try right now), but perhaps GOTO on the current slide may break current action sequence (not a good solution though).
The other way is to check some condition with IF on all FOR action sequence. If condition is met, then action sequence is executed, if not - just empty cycle.
 
 
Thanks a lot for your answers, Nick and Slav!

I have to create a stopwatch. A click on a Stop-Button shall stop the for-cycle (within there is a timer-action) and the actual value of the iteration is given to a variable.
Next I will try a solution with the if-statement and the empty cycle. I think it might be a first solution.

Thank you very much!
 
If you know where you want it to stop and can capture the value before you start the loop then you can use a #var_name for the to stop point.
The loop count itself is a variable so you should be able to refer to it in the IF statement ... #mycount>=50
Then a return at the end.
If its put in as a linear sequence then I think the count will iterate up to its max value then look at the folowing statements.
It might be a use for 'parallel' when each iteration will(??) be checked against the IF statement.
Whats the loop for??
Subject:
Message options
No additional options