IF - THEN (-ELSE) is conditional statement in Petit Computer. The full syntax is
IF condition THEN statement [ELSE statement]
Conditions may optionally be surrounded by parentheses. Multiple statements may be included after
ELSE with the
: separator. The
ELSE and subsequent commands are optional; if included, those commands will be executed when condition is not satisfied.
Conditions are often written with Relational Operators, e.g.
IF X < 10 THEN .... Additionally:
- The form
IF X THEN ...will execute the
THENbranch unless X is 0
- The form
IF !X THEN ...will execute the
THENbranch only when X is 0 (see ! (Operator))
Of note is the arguably poor decision not to include support for multiline IF-THEN-ENDIF statements. While IF statements can be used with multiple commands via the : separator, this quickly becomes too long to comfortably read and edit on a DS:
IF X==5 AND Y==10 THEN Z=25:PRINT "Condition satisfied!":END ELSE X=X+1:Y=Y-1
It is often preferable to use a GOTO or GOSUB instead of appending multiple commands with
:. Several older BASIC dialects only allowed IF statements to call GOTO or GOSUB.
Petit Computer's sequel, SmileBASIC for the 3DS will allow multiline IF statements in the form:
- IF condition THEN
- one or more lines of statements