Knowledge Card - Loop Types

Loop Types

  1. For Loop: Repeats a block of code a specific number of times.

    • Example: for i in range(5): print(i) prints numbers from 0 to 4.
  2. While Loop: Repeats a block of code while a condition is true.

    • Example: while x < 10: x += 1 increments x until it reaches 10.
  3. Nested Loops: Loops inside other loops.

    • Example: for i in range(3): for j in range(2): print(i, j) creates a grid of values.