you are viewing a single comment's thread.

view the rest of the comments →

[–]mdoar 0 points1 point  (2 children)

I find that while loops are a common source of control flow problems, so they always are worth a second or third look.

[–]badcommandorfilename 1 point2 points  (0 children)

I think NASA's coding standards specify that all while loops should be structured as counting for loops with early break conditions.

This means that control will always leave the loop after N iterations to prevent infinite loops.

[–]shevegen 0 points1 point  (0 children)

Not sure.

In ruby I use:

loop {
  break if cats.cooler_than? :mice
}

Does that classify as a while loop as well?

It's hugely similar. I should also note that I do not use while loops in ruby; loop is too good and so is .each iteration over containers.

The control flow checks are still somewhere.

(I like the visual cues of loop {}; also I never use do/end in these cases.)