3. If-Else statements and loops#

So far, the statements in the code blocks we have seen have executed sequentially, meaning each statement would be executed after the previous statements have finished executing. However, this is not always the case. Sometimes, based on some condition, some statements should be executed and others should be ignored. In other cases, some statements should be executed repeatedly until some condition fails. This is where conditional statements and loops become helpful. They are fundamental to every piece of software.

Chapter Summary

  • Algorithms and Pseudocode

  • Conditional Statements

    • if, if-else, if-elif-else

    • ternary operator

  • Loops

    • while, for, nested loops, for with else statement

    • range() function

    • continue, break, pass statements