Could the both the true branch and the
false branch of an IF
contain nested IF
s?
Yes. Control structures fit together like Lego blocks to build up complicated programs.
Here is a sample run of the program:
Please enter the base rate 1000 Please enter annual mileage 15000 Your base rate is 1000 Your discount is .05 You pay 950
Here is how the program ran. The statements are numbered in the order that they executed:
'Car insurance program (1)PRINT "Please enter the base rate" (2)INPUT BASERATE (3)PRINT "Please enter annual mileage" (4)INPUT MILEAGE <--- gets 15000 (5)IF MILEAGE < 20000 THEN true---so nested IF executes (6) IF MILEAGE < 10000 THEN false LET DISCOUNT = .1 ELSE (7) LET DISCOUNT = .05 false branch of nested IF executes END IF ELSE LET DISCOUNT = 0 END IF (8)PRINT "Your base rate is", BASERATE (9)PRINT "Your discount is", DISCOUNT (10)PRINT "You pay", BASERATE * (1 - DISCOUNT) END
Will the last three PRINT statements execute no matter what MILEAGE is?