Often it is needed to perform an action only if some conditions are fulfilled. And IF THEN ELSE command serves this purpose.
Code: Select all
INPUT N
PRINT "Number";N;
IF EVEN (N) = 1 THEN PRINT "is even" ELSE PRINT "is odd"
Code: Select all
INPUT A,B
IF A < B THEN
PRINT A;"is less than";B
ELSE
IF A = B THEN
PRINT A;"is equal to";B
ELSE
PRINT A;"is greater than";B
END IF
END IF
IF THEN ELSE is working like that: after IF there is a condition. If this condition is true then code after THEN is executed. If condition is false then code after ELSE is executed. Also ELSE part can be absent, so it could be written like that:
Code: Select all
INPUT A,B
IF A < B THEN PRINT A;"is less than";B
IF A > B THEN PRINT A;"is greater than";B
IF A = B THEN PRINT A;"is equal to";B
Code: Select all
INPUT N
PRINT "Number";N;
IF EVEN (N) THEN PRINT "is even" ELSE PRINT "is odd"
Code: Select all
INPUT X,Y
IF X > 0 OR Y > 0 THEN PRINT "At least one number is greater than zero"
IF X > 0 AND Y > 0 THEN PRINT "Both numbers are greater than zero"
Write a program which fills the screen with random circles when device is oriented horizontally and with random lines when device is oriented vertically.