In selection control structures, conditional statements are features of a programming language which perform different computations or actions depending on whether a programmer-specified Boolean condition evaluates to true or false.
The basic attribute of a selection control structure is to be able to select between two or more alternate paths. This is described as either two-way selection or multi-way selection. A question using Boolean concepts usually controls which path is selected. All of the paths from a selection control structure join back up at the end of the control structure, before moving on to the next lines of code in a program.
If Then Else Control Structure
The if then else control structure is a two-way selection.
If age > 17 Output "You can vote." False: Output "You can't vote." End
Case Control Structure
The case control structure is a multi-way selection. Case control structures compare a given value with specified constants and take action according to the first expression to match.
Case of age 0 to 17 Display "You can't vote." 18 to 64 Display "You're in your working years." 65 + Display "You should be retired." End
Python does not support a case control structure. There are workarounds, but they are beyond the scope of this book.
- if then else
- A two-way selection control structure.
- A multi-way selection control structure.