Conditions Summary
In this chapter, we learned how our program can decide what to do using conditions. We found out that:
- The
if
statement executes the following block of code if its condition is true. - The
if
statement can be followed by anelse if
statement, which can have another condition that, when true, executes the block of code of theelse if
statement. - The
if
orelse if
statement can be followed by anelse
statement. The block of code of theelse
statement is executed if all conditions of theif
,else if
statements were false. - After the first true condition, the given block of code is executed and the rest of the conditional is skipped.
- We perform comparisons using the following operators:
==
- Equals!=
- Not equals>
- Greater than>=
- Greater than or equal<
- Less than<=
- Less than or equal
- The block of code following the curly brace must be indented.
- There are two boolean values:
true
(true),false
(false). - Using logical operators
&&
(and),||
(or) we can combine multiple conditions. - Using the
!
(negation) operator we can reverse a condition fromtrue
tofalse
or fromfalse
totrue
. - Nested conditions are those that are in the code block of another condition.
Congratulations on completing the chapter about conditions! In the next lesson, we'll dive into the world of vectors and explore their amazing possibilities in programming. Get ready for an adventure full of efficient data storage and manipulation!
Instructions
Look at the example code that demonstrates all the conditional concepts we learned in this lesson. When you're ready, you can continue to the next lesson!
Start programming for free
10/10