The Loop Command


Command Summary

Repeats a block of code forever.

Command Syntax

(block of code)

Menu Location

Starting in the program editor:

  • Press F2 to enter the Control menu.
  • Press 6 to paste Loop..EndLoop.

Calculator Compatibility

This command works on all calculators.

Token Size

2 bytes for Loop;
4 bytes for EndLoop.

A Loop..EndLoop block is used to make the code inside the Loop repeat forever. For example, the following code will keep printing "Hello!" until you break out of the program with the ON key or the calculator runs out of batteries:

: Disp "Hello!"

Generally, Loop isn't used just like that, because having to end a program with the ON key lacks style. There are two ways to break out of the loop:

  • using Goto, you can jump to somewhere else in the program.
  • using Exit, you can exit the loop, continuing the program immediately after the EndLoop command.

Generally, using Exit is considered more stylish — and it's easier to read the code, because you don't have to search the entire program for the Goto's matching label.

Error Conditions

730 - Missing start or end of block syntax happens when the Loop is missing an EndLoop, or vice versa.

Related Commands

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License