The End command is used together with the different control structures, including the If conditional, While loop, Repeat loop, and For( loop, to indicate the end of the code block for the respective control structure. In the case of the If conditional, you also need to add a Then command, which is used to indicate the beginning of the control structure.
You can prematurely end a control structure by using a lone If conditional, and then having End be its executed command. Because the calculator stores the positions of the End commands, it will take this End command to be the End command of the control structure.
:If <condition> :End
One of the most important features of the End command is putting multiple control structures inside of each other (known as nesting). While you typically nest If conditionals inside of loops, you can actually nest any control structure inside of any other control structure -- this even works when using the same control structure, such as a While loop inside of another While loop.
When nesting control structures, you need to remember to put the appropriate number of End commands to close the appropriate structure. The easiest way to keep track of lots of nested control structures is to code the first part, add an End immediately after the beginning, and then hit 2nd DEL on the line with the End, then hit ENTER a lot of times.
- ERR:INVALID occurs if this statement is used outside a program.
- ERR:SYNTAX occurs if this statement is used before a logic block has been initiated.