Back to OmaTips

While Willy Wiggles Wormlike Whatsomatalkingabout?
While is kind of like a /loop and an /if combined. It's a looping process that will continue until a given statement comes up false.

Keep in mind, when I say "until a given statement comes up false, that means exactly that. FALSE. /while {$0!=1} ... just because it's Does-Not-Equal doesn't mean it's false. If "$0" was 2, the statement is definitely TRUE. if $0 is 1, then the statement is indeed false.

Care must be used to ensure that the condition will eventually be false, so that you don't get a stack fault (memory get's overfilled) and MM crashes.

/var {MyVar} {1} /while {$MyVar<=100} {/math {MyVar} {$MyVar+1}} Simple example. Made MyVar value of 1. Then the while loops and as long as MyVar isn't 100 or more, it'll add +1 to the value of MyVar. Once MyVar is >100 the while will stop (condition is now false).

/while is very handy when used with care. The combination of the looping process and condition(s) make it pretty powerful in certain circumstances. See my tip about making a "wait" command for another example of using /while.

Notes:
In the condition you can use "&&" just like in an /if. But you can't use "||" (or).

There is no "else do", syntax is: /while {condition(s) are true} {do}