Page 3: Combining Conditionals
Unit 2 , Lab 3, Page 3
On this page, you will learn about nested conditional statements.
-
Here are four possible ways to define
≥
. Discuss what advantages each style has:- Do they all work correctly?
- Which seem elegant because they are short?
- Which seem elegant because they are clear?
- Which seem elegant because the steps are simple?
- Which is closest to how you think about ≥ in math class?
- Which seems clearest to you?
A nested conditional statement is an if
or if else
statement inside another if else
statement.
Look back at the first two examples in the previous problem. Since the predicate expression a =
b will report true when they are equal and false otherwise, it’s unnecessary to use the nested conditional statement in the first example, and the second example using the predicate inside the else
part is sufficient. Sometimes, however (especially when you aren’t building a predicate), it can be helpful to use nested conditional statements.
-
Describe what this code segment will do.
- Look back at your code for writing on the stage in three colors. If it doesn’t already use a nested conditional statement, copy the code, and create a new version that does.
-