Difference between revisions of "83Plus:Basic:While"
(unicoded) |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 13: | Line 13: | ||
Use of a Goto statement within an While statement will cause an increase in memory allocation, leading to program slowdowns and eventually a MEMORY error. For example, the following code will eventually cause an error: | Use of a Goto statement within an While statement will cause an increase in memory allocation, leading to program slowdowns and eventually a MEMORY error. For example, the following code will eventually cause an error: | ||
− | <nowiki> | + | <nowiki> |
Lbl 0 | Lbl 0 | ||
While X=1 | While X=1 | ||
− | X+ | + | X+1→X |
Disp X | Disp X | ||
Goto 0 | Goto 0 | ||
Line 23: | Line 23: | ||
If you must use a Goto within an While statement, it is possible to trick the 83+ into thinking the block ended by jumping to an otherwise unused label that uses an End statement followed by a jump to the proper label. For example, the above program could be rewritten like so: | If you must use a Goto within an While statement, it is possible to trick the 83+ into thinking the block ended by jumping to an otherwise unused label that uses an End statement followed by a jump to the proper label. For example, the above program could be rewritten like so: | ||
− | <nowiki> | + | <nowiki>0→X |
Lbl 0 | Lbl 0 | ||
While X=1 | While X=1 | ||
− | X+ | + | X+1→X |
Disp X | Disp X | ||
Goto 2 | Goto 2 | ||
Line 37: | Line 37: | ||
This would avoid the problem by causing the 83+ to terminate the While conditional prior to jumping. | This would avoid the problem by causing the 83+ to terminate the While conditional prior to jumping. | ||
− | |||
== Examples == | == Examples == | ||
− | <nowiki> | + | <nowiki> |
− | + | While G≠105 | |
− | + | getKey→G | |
− | + | End</nowiki> | |
− | </nowiki> | + | |
Or, if you desire the use of other operators, such as And, Or, or Xor: | Or, if you desire the use of other operators, such as And, Or, or Xor: | ||
− | <nowiki> | + | <nowiki> |
− | + | While X=5 and Y≠3 | |
− | + | Input "",A | |
− | + | A+X→Y | |
− | + | End</nowiki> | |
− | </nowiki> | + |
Latest revision as of 16:49, 9 December 2005
Synopsis
Token Size: 1 byte
Syntax:
- While condition
- command
- End
The while command is used to execute a command or series of commands when a variable shares a given relationship with another variable or a value. A While command will continue to execute everything before the next End until the given condition is no longer met.
Comments
Use of a Goto statement within an While statement will cause an increase in memory allocation, leading to program slowdowns and eventually a MEMORY error. For example, the following code will eventually cause an error:
Lbl 0 While X=1 X+1→X Disp X Goto 0 End
If you must use a Goto within an While statement, it is possible to trick the 83+ into thinking the block ended by jumping to an otherwise unused label that uses an End statement followed by a jump to the proper label. For example, the above program could be rewritten like so:
0→X Lbl 0 While X=1 X+1→X Disp X Goto 2 End Return Lbl 2 End Goto 0
This would avoid the problem by causing the 83+ to terminate the While conditional prior to jumping.
Examples
While G≠105 getKey→G End
Or, if you desire the use of other operators, such as And, Or, or Xor:
While X=5 and Y≠3 Input "",A A+X→Y End