UserGuide - LoopsData, Events or many other things can also be processed using loops, which are always checked for a specific condition. Loops can be: Repeat : Until, Repeat : Forever, While : Wend, For : Next, ForEach : Next.
Define.i A For A = 0 To 10 Step 2 Debug A Next AThis loop will increment the variable B by a random amount between 0 and 20 each time, until B exceeds 100. The number of iterations actually performed in the loop will vary depending on the random numbers. The check is performed at the start of the loop - so if the condition is already true, zero iterations may be performed. Take the ; away from the second line to see this happen.
Define.i B ; B = 100 While B < 100 B + Random(20) Debug B WendThis loop is very similar to the last except that the check is performed at the end of the loop. So one iteration, at least, will be performed. Again remove the ; from the second line to demonstrate.
Define.i C ; C = 100 Repeat C + Random(20) Debug C Until C > 99This loop is infinite. It won't stop until you stop it (use the red X button on the IDE toolbar).
Define.i D Repeat Debug D ForEverThere is a special loop for working with lists and maps, it will iterate every member of the list (or map) in turn.
NewList Fruit.s() AddElement(Fruit()) Fruit() = "Banana" AddElement(Fruit()) Fruit() = "Apple" AddElement(Fruit()) Fruit() = "Pear" AddElement(Fruit()) Fruit() = "Orange" ForEach Fruit() Debug Fruit() Next Fruit()
< Previous: Decisions & Conditions | Overview | Next: String Manipulation >