While

From MiniScript Wiki
Jump to navigation Jump to search

while is a keyword used to loop as long as some condition is true. The condition is tested before each iteration of the loop (including the first). When the condition is not true, execution jumps to the next statement after end while.

Within the loop, execution may skip directly to the next iteration with continue, or jump out of the loop by using a break statement.

Example

bunnies = 2
while bunnies < 200
    print bunnies + " bunnies"
    bunnies = bunnies * 2
end while
print "Too many bunnies!"

Output:

2 bunnies
4 bunnies
8 bunnies
16 bunnies
32 bunnies
64 bunnies
128 bunnies
Too many bunnies!