4.5 Code block, conditions
This lesson refines the if/else pattern. We start from if (value < 10): when the test is true, the block that follows runs and prints the value. We add an else branch (the French "sinon") that prints "the value is not less than 10". With the value set to 11, the first test fails so the program jumps straight to the else block.
If we flip the condition to if (value >= 10) and rerun the program, the first branch is taken and the else is ignored. That is the classic two-branch shape of an if/else: only one of the two blocks is executed.
Going further with else if
if (value > 10)handles the strictly greater case.else if (value == 10)handles the exact equality.elsecovers everything else.
With the value set to 10, the first test (> 10) is false, so execution moves on to the else if (value == 10) branch, which is true, and prints the matching message. The final else is only reached when none of the previous conditions are validated. In the next lessons we will keep playing with if and explore boolean operators to combine several conditions inside one test.