While Statement

Repeatedly execute code while a condition is true.
Evaluate the condition either before executing the code ( the first time) or afterwards.


[post] while <expression>

Without the post, the expression is first evaluated and while true, the statements are executed.
If the expression evaluates false the first time, the statements will not be executed.

With post, the condition is evaluated after the statements execute, so the statements will execute at least once.

Inside the statements, a break statement will exit the loop and a continue statement will skip the remaining statements and cause evaluation of the expression again. In either case, an if statement should be used to control when the loop is broken or continued (otherwise it would be pointless to have further statements in the loop).

# Example 1
while obj.someCondition

# Example 2
while node
    print node
    node =

# Example 3
while node
    if not node.isActive
        print 'skipping inactive node: [node]'
    print node
    node =

# Example 4
while true
    input = Console.readLine
    if input is nil or input.trim.toLower == 'exit'

# Example 5
post while line and line.trim == ''
    line = stream.readLine