Control Flow

Control Flow#

  • Programming languages define statements to control the flow of execution of the program

  • Control flow constructs in Python

    • Conditional statements

      • if and match

    • Iteration statements or loops

      • Count-controlled loops

        • The for statement

        • Iterates over each element of an iterable object (e.g., sequence datatypes)

      • Condition-controlled loops

        • The while statement

        • Executes a code repeatedly as long as a condition stays true

  • The if, match, for, and while statements are compound statements

    • Typically span multiple lines of code