if... else allows us to make decisions, this is also called branching in programming. The execution of code is not linear anymore, it branches out and merges back at end of the branches as shown below.
In the "if" flowchart, the "trueBlock" is only executed when "booleanTest" is true. In the "if... else..." flowchart, the "trueBlock" is executed when "booleanTest" is true and "falseBlock" is executed when "booleanTest" is false.
Note here the "trueBlock" and "falseBlock" are referring to the code blocks that are marked by indentations. It's critical to know where each block starts and ends.
B. HW: write if or if... else... statements to solve the problems below. Add comments to indicate where the beginning and end of each "trueBlock" and "falseBlock" are.
Given three integers, print them in ascending order.
Given five integers, print the least of them.
(Optional Challenge) Given the year number. You need to check if this year is a leap year. If it is, print LEAP, otherwise print COMMON.
The rules in the Gregorian calendar are as follows:
a year is a leap year if its number is exactly divisible by 4 and is not exactly divisible by 100
a year is always a leap year if its number is exactly divisible by 400
Note: The words LEAP and COMMON should be printed in all caps.