Alternatively, this abomination:
i has to remain true for the
for loop to keep running. When it hits
0 it is false and so stops. Counting down instead of up lets us save 2 characters over
The code also has no spaces or semicolons- bad, I know. But with just one line, it still works!
The ternary operator reads "If
i divided by 2 equals 0 (so if
i is 2), print
iii; otherwise, print
i i." This means only the second line will print
while loop was a test that didn't get any fewer bytes, but was interesting.
i is just defined outside of the loop. I didn't know that you could iterate inside of the while statement; it still goes until
0 from what I can tell. I don't know if this works cross-browser, but it worked in Chrome. I can't help but think there's a way to shorten the
while version more, but I haven't figured it out yet...