ExamplesConditions
Conditions
Practical branching examples using IF, ELSE, comparisons, and logical expressions.
On this page
Conditions choose which instructions a program executes.
Simple IF
simple-if.msp
temperature = 28IF temperature > 25 THEN PRINT "Warm"ENDIF and ELSE
Exactly one branch runs.
if-else.msp
score = 72IF score >= 50 THEN PRINT "Passed"ELSE PRINT "Try again"ENDEven or odd
MOD returns the remainder after division.
even-odd.msp
number = 14IF number MOD 2 = 0 THEN PRINT "Even"ELSE PRINT "Odd"ENDMaximum of two values
maximum.msp
first = 5second = 8IF first > second THEN PRINT firstELSE PRINT secondENDTest each condition with values on both sides of the boundary and with a value exactly on the boundary.