SyntaxRepeat while trueBoolean (* code statements *) end repeat Descriptionrepeat while keeps executing its enclosed script code as long as the boolean expression following while is true: repeat while theTruth is true...end repeat If the boolean expression that follows while returns false, then the repeat while loop is terminated, and its enclosed script code will not execute anymore. Script execution then resumes after the end repeat part of the repeat while statement. repeat while has the opposite effect of repeat until; it keeps executing as long as some boolean expression is true, whereas repeat until keeps executing until something is true. You can also use exit within repeat while to leave the loop. In general, Repeat loops can contain nested repeat loops, as well as other flow-control statements such as if and tell. ExamplesThis code shows how to use repeat while: set theCount to 0 repeat while (theCount < 5) set theCount to theCount + 1 log theCount end repeat The two code lines within this repeat while statement block will continue executing (thus increasing the value of theCount by one) while theCount is less than 5. Each cycle through the loop tests the boolean expression: theCount < 5 and, as long as this expression returns true, the enclosed code will execute again. The variable theCount actually reaches 5 in the following code. This is because it is eventually incremented to 4, then the: repeat while (theCount < 5) executes and, since theCount is still less than 5, the enclosed script code executes once more, increasing the variable's value to 5. |