Repeat...Until loops
 

The final type of loops to be discussed are Repeat...Until loops. They work in a slightly different way to the previous types of loops and their format is:
Repeat
Code sequence
Until <Expression>

The way this type of loop works is that the code inside the loop will be executed until the value of the expression is true. Specifically what happens is this; the loop starts and the code inside it is executed. At the end of the loop, the value of the expression is calculated and if it is false, the program returns to the start of the loop. If the value of the expression is true, the program will continue to the line after the end of the loop. The important differences of this type of loop is that the inner code sequence will always be executed the first time round the loop, and the loop exits when the value of the expression reaches true. Some examples of using Repeat...Until loops:

Code DEFTYPE.w i

; Notice the loop will continue /until/ i = 10
; If you used a while loop, you would probably need a different
; comparison operator
Repeat

NPrint "First loop, counting: ",i
i+1
Until i=10

; This loop will only work once, since the expression is true immediately
i = 0
Repeat

NPrint "Loop2, counting: ",i
i + 1
Until i < 10

MouseWait
End

There is also the command Forever which you can use in place of the loop expression. This will make the loop an endless one (the same as using "Until 0") which never exits unless you use some of the commands described in the next few sections.


Previous: While...Wend loops Programming contents Next: Nested loops


News | Introduction | Search | List/Forum/IRC Webring | Contact
Installation | Troubleshooting | Programming | Archives | Links
Return to programming main
Page last modified: 6th February 2002