Difference between revisions of "83Plus:Basic:If"
(→Synopsis: + If...Then...Else...End) |
|||
(5 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
− | [[Category:83Plus:Basic:Conditionals|If]] | + | [[Category:83Plus:Basic:Conditionals|If(...Then(...Else)...End)]] |
== Synopsis == | == Synopsis == | ||
'''Token Size:''' 1 byte | '''Token Size:''' 1 byte | ||
Line 16: | Line 16: | ||
''commands'' | ''commands'' | ||
Else | Else | ||
− | ''commands'' | + | ''commands-else'' |
End | End | ||
− | + | In the first from, ''command'' is executed if and only ''condition'' evaluates to anything other than 0. In the second form and third form, ''commands'' is also executed if and only if ''condition'' is not zero. In the third form, if ''condition'' is zero, ''commands-else'' is executed. | |
== Comments == | == Comments == | ||
Line 65: | Line 65: | ||
Disp "MODE" | Disp "MODE" | ||
If K=32 | If K=32 | ||
− | Disp "X,T,''θ'',''n''" ;''θ'' == Alpha+0. To get the italic n, switch to Seq mode and press the X,T,''θ'',''n'' key. | + | Disp "X,T,''θ'',''n''" ;''θ'' == Alpha+0. To get the italic n, switch to Seq mode and press the X,T,''θ'',''n'' key or choose it from the Catalog. |
Latest revision as of 11:48, 19 July 2005
Synopsis
Token Size: 1 byte
Syntax:
If condition command
If condition Then commands End
If condition Then commands Else commands-else End
In the first from, command is executed if and only condition evaluates to anything other than 0. In the second form and third form, commands is also executed if and only if condition is not zero. In the third form, if condition is zero, commands-else is executed.
Comments
Repeated use of a Goto statement within an If:Then 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:
0->X ;-> == STO operator Lbl 0 If 1 Then X+1->X Disp X Goto 0 End
If you must use a Goto within an If:Then 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 If 1 Then 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 If:Then block prior to jumping.
Since TI-BASIC has no equivalent of what real BASIC calls Select Case, multiple Ifs must be used in cases where a variable needs to be checked against multiple values.
Examples
A particular example is a keyloop. Assuming a keycode was stored in K, a sequence of If statements would compare K to the corresponding integer key value.
If K=21 Disp "2ND" If K=31 Disp "ALPHA" If K=22 Disp "MODE" If K=32 Disp "X,T,θ,n" ;θ == Alpha+0. To get the italic n, switch to Seq mode and press the X,T,θ,n key or choose it from the Catalog.