Conditions Summary
In this chapter, we learned how our program can decide what to do using conditions. We found out that:
- The
ifstatement executes the following block of code if its condition is true. - The
ifstatement can be followed by anelse ifstatement, which can have another condition that, when true, executes the block of code of theelse ifstatement. - The
iforelse ifstatement can be followed by anelsestatement. The block of code of theelsestatement is executed if all conditions of theif,else ifstatements 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 fromtruetofalseor fromfalsetotrue. - 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