Rexx Programming/How to Rexx/while

"While" loops are a kind of indefinite loop. They repeat the same piece of code as long as a certain condition is true. They contain code within them which may be repeated an unknown number of times. The while loop checks the condition before even starting to run this code, and then it checks the condition again after the code completes to see whether it should run the code again.

/* Let's start our counting at 1. */
count = 1
/* The first loop will be skipped over entirely, since the condition is false. */
do while count < 0
 say "You'll never see this!"
end
/* The following loop will count to 10 and then stop because count will be 11. */
do while count <= 10
 say count
 count = count + 1
end
/* The message about apples will only be said once, while count is still 11. */
do while count < 12
 say "An apple a day keeps the doctor away."
 count = count + 1
end

Be warned that a while loop will not stop on its own if the loop condition is never false. It will be an infinite loop. This is a common mistake.

/* Just keeps on saying hello. */
do while 2 < 3
 say "Hello, world!"
end