According to the doc, the while
statement executes the block as long as the expression is true. I wonder why it becomes an infinite loop with an empty expression:>
This is a special case. An empty condition expression defaults to just true
, which means "loop forever, or until a break
. In C (and perl) the idiom
for(;;) {
// Neverending fun
}
has the same effect for the same reason.
There doesn't appear to be any mention of this in the official perl docs, and yet there is a special rule in the parser for it. Perhaps it's because nobody uses it :)
The for(;;)
idiom is less uncommon though.