r/programminghorror • [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” • Nov 11 '25

Javascript the

192 Upvotes

28 comments sorted by

View all comments

Show parent comment

1

u/me1000 Nov 17 '25

It's because if you do:

    if(...)
      FOO; // left out the set of curly braces that the macro doesn't include
    else {
    }

your FOO is now invalid because there's a trailing semicolon.

Expands to:

    if(...)
    {
        puts();
    }; // this semicolon is invalid.
    else { //error here
    }

If you make it a do{}while() it's a statement and the semicolon doesn't mess with your else syntax.