Hacker News new | ask | show | jobs
by ZhuanXia 2257 days ago
Not a Perl guy. What are the semicolons in that if statement all about?
3 comments

It's a C idiom. Some people prefer `for(;;)` over `while(1)` to create infinite loops.
I see. Just a c-style loop absent conditions. I find it kind of ugly for some reason.
Weird, since Raku has `loop { }` that means exactly that. I guess the author was not aware of it (or just doesn't like it).

EDIT: Oh, that's in the Perl (5) code. Nevermind then.

In C-like it kind of makes sense – it's 1 character shorter, and on some ancient crappy compilers it may actually run faster than while(1) since it doesn't have to check the condition every time ;)

I thought it was just some old weird hate on the while() construct. I remember a long time ago people advocating for using for() always for looping because that way the language was more regular. I thought it was a weird argument.
Did you mean “for(;;)”? I didn’t notice semicolons in an if-statement. In the for-loop, it means “forever loop.” There is no declaration , check, iterate parts in the loop. You may be more familiar with “for(i=0; i<10; i++)”
I think it is usually written as while(1) { ... }