Exiting Loops and Programs

Program loops are designed to continue until a condition is met or after a specified number of iterations. The break operator allows you to prematurely exit a loop, while the continue operator allows you to skip an iteration. The return operator allows you to prematurely exit a program out of the context of a loop.

break

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

break operator

The break operator halts execution of the current loop and returns the last value calculated. The break operator is used in conjunction with a conditional statement to halt execution of a loop and return control to the first statement after the loop. This operator takes no arguments.

continue

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

continue operator

The continue operator skips the remainder of the current iteration and returns to the first loop statement. In a for loop, the iteration variable is incremented. The continue operator is used in conjunction with a conditional statement to skip the current iteration and proceed to the next one. It takes no arguments.

return

Keystroke: [Ctrl] [Shift] \ Do not type the word "return" it does not produce the operator.

return x

The return operator halts the program and returns x.

Examples:

break operator

continue operator

return operator

QuickSheet 1 - Break and Continue
QuickSheet 2 - Return

Notes:

Related Topics