FANDOM


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 THEN or ELSE with the : separator. The ELSE and subsequent commands are optional; if included, those commands will be executed when condition is not satisfied.

ConditionsEdit

Conditions are often written with Relational Operators, e.g. IF X < 10 THEN .... Additionally:

  • The form IF X THEN ... will execute the THEN branch unless X is 0
  • The form IF !X THEN ... will execute the THEN branch only when X is 0 (see ! (Operator))

Multiple conditions may be considered with the AND, OR, and XOR operators, e.g.: IF X AND Y OR B THEN .... The precedence of operators is given on the page List of Operators.

NotesEdit

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
ENDIF

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.