For

The for loop is your go-to when you already know how many times you want something to run.
Different from while/do…while (which depend on conditions changing), the for loop is basically a tiny “counter machine” with three parts:

for (start; condition; step) {
    // repeat this
}

How it Thinks:

  • Start: Run once before the loop begins — usually sets a counter ($x = 0)
  • Condition: Checked before each iteration — if false, loop stops
  • Step: Runs after each loop — usually increments/decrements the counter ($x++)

Why it's useful in real MP/Pretty Links debugging:

  • Perfect when iterating over a fixed amount of items (10 rules, 50 test links, etc.)
  • Great for generating test output while debugging user snippets (e.g., simulating 20 renewals)
  • Predictable — no risk of infinite loops unless you do something wild with the condition

Quick example

for ($x = 0; $x <= 10; $x++) {
  echo "The number is: $x";
}

break & continue (same as other loops)

  • break = stops the entire loop
  • continue = skips the rest of this iteration and moves to the next

Counting by custom steps

for ($x = 0; $x <= 100; $x += 10) {
  echo $x;
}