Program Loops

A loop is a block of code that causes one or more statements (the body of the loop) to iterate until a termination condition occurs. There are two kinds of loops:

For Loops

Keystroke: [Ctrl] " Do not type the word "for." It does not produce the operator.

Evaluates z for each value of x over the range y. Typically, at least one expression in the loop body, z, uses the value of x to change the calculation for each evaluation. Use a for loop when you know exactly how many times you want the body of the loop to execute.

Operands:

Example:

The for operator

Notes:

QuickSheet

While Loops

Keystroke: [Ctrl] ] Do not type the word "while." It does not produce the operator.

Evaluates y while x is nonzero (true). The condition expression is evaluated at the beginning of the while loop, so it is possible that the loop never executes. The loop stops iterating as soon as the condition is false and returns the last value calculated in its body on the previous iteration.

Operands:

Example:

The while operator

QuickSheet

Related Topics