Control structures explained in human terms

Website buildingToday I found myself on IRC chat again, while debugging some code. During a rather childish “am not, are too” discussion I typed the line “while (true) { echo ‘not’; }”, effectively ending the debate, when someone asked me if this was a valid statement.

I then proceeded to explain it was valid and soon ended up in a discussion whether such a statement would be wise. I found myself trying to explain in simple terms what controls there are to a while control structure.

I ended up with this analogy:

If the while-loop is an alarm clock:

  • the condition is its battery;
  • the continue()-statement is its snooze button;
  • and the break()-statement is the hammer you use on it.

That stuck. 😉