Conditions Summary

In this chapter, we learned how our program can decide what to do using conditions. We found out that:

  1. The if statement executes the following block of code if its condition is true.
  2. The if statement can be followed by an else if statement, which can have another condition that, when true, executes the block of code of the else if statement.
  3. The if or else if statement can be followed by an else statement. The block of code of the else statement is executed if all conditions of the if, else if statements were false.
  4. After the first true condition, the given block of code is executed and the rest of the conditional is skipped.
  5. We perform comparisons using the following operators:
    • == - Equals
    • != - Not equals
    • > - Greater than
    • >= - Greater than or equal
    • < - Less than
    • <= - Less than or equal
  6. The block of code following the curly brace must be indented.
  7. There are two boolean values: true (true), false (false).
  8. Using logical operators && (and), || (or) we can combine multiple conditions.
  9. Using the ! (negation) operator we can reverse a condition from true to false or from false to true.
  10. 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

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

10/10

Conditions Summary | Start Coder