Search⌘ K
AI Features

Control Flow

Explore how to use Python control flow elements such as if, elif, and else statements, nested conditionals, and loops like while and for. Understand these tools to write scripts that handle multiple conditions and repetitive tasks, essential for automating web security assessments.

Conditional statements

Let’s first discuss conditional statements. These allow us to perform certain sets of actions in our script, depending on certain sets of other actions or flags.

For example, assume we’re making a script that takes a number from the user as input, and we want it to:

  • Print + when the number is positive.
  • Print - when the number is negative.
  • Print = when the number is zero.

This can be achieved with the if, elif, and else ...