Table of contents

Flow Control Statements

used to control the execution flow of a program, allowing certain operations to be performed either once or repeatedly based on conditions. Your classification of flow control statements into three types 

These statements allow the program to make decisions and execute specific blocks of code based on conditions.

Examples:

  • If: Executes a block of code if a condition is true.
  • if-else: Executes one block if the condition is true, another if false.
  • if-elif-else: Handles multiple conditions.
  • Nested if: Conditions within conditions.
  • Match-Case: Handle multiple cases.

These statements allow repeated execution of a block of code until a condition is met or for a specific number of iterations.

Examples:

  • for: Iterates over a sequence (e.g., list, string, range).
  • while: Repeats as long as a condition is true.
  • To perform operations repeatedly, either for a finite number of times or until a condition becomes false.

These statements modify the behavior of loops or serve as placeholders.

Examples:

  • break: Exits the loop immediately.
  • continue: Skips the current iteration and moves to the next.
  • pass: Acts as a placeholder, doing nothing (used when syntax requires a statement but no action is needed).
  • To fine-tune loop behavior or reserve space for future code.