in reply to while () vs. while (1)

I've known about this behaviour for a long time. I think it's because while (EXPR) { } is treated as if it were for (;EXPR;) { }. And for (;;) { } is, just as in C, an infinite loop.

Note that Deparse turns both while () {} and for (;;) {} into while (1) {}.

Replies are listed 'Best First'.
Re^2: while () vs. while (1) (trivia)
by ikegami (Patriarch) on Jan 24, 2011 at 16:21 UTC

    Note that Deparse turns both while () {} and for (;;) {} into while (1) {}.

    All three are identical in the optree, but it's closer to while () {}. No "1" constant exists. All C-style for loops, while loops and bare loops ("{ ... }") are implemented using the same loop op. The condition of "while (1)" is completely optimised away.