Loops Cheatsheet

Standard Loop

for i := 0; i < 10; i++ {
    // ...
}

“While” Loop

for condition {
    // ...
}

Infinite Loop

for {
    // ...
}

Control Flow

  • break: Exit the loop.
  • continue: Skip to the next iteration.

Logic & Operators

  • Modulo: i % 2 == 0 (Check for evens).
  • AND: &&
  • OR: ||
  • NOT: !

Key Reminders

  • There is no while keyword in Go.
  • Semicolons are only needed when you have more than one section in the for statement.
  • Use continue to avoid deep nesting of if statements inside loops.