The while Statement

The while loop has the following form:

while condition statement


While the condition is true, the statement or block of statements is repeatedly executed. When the condition becomes false, the loop is terminated and execution resumes at the statement after the while loop. The condition is tested at the top of the loop, which means that in some circmstances, the statement is not executed at all.

This program calculates the primes less than 100.

// primes - calculate the primes less than +eh

space primes
        i = +c
        while i < +eh
           is_prime = true

            g = +c
            limit = i / +c

            while g <= limit
                if i % g == 0 {is_prime = false break}

            if is_prime cout << i << " is prime\n"