r/programming • u/balazsbotond • Aug 30 '15
JavaScript “maze generator” in a tweet
https://twitter.com/botond_balazs/status/637960240055615488
841
Upvotes
r/programming • u/balazsbotond • Aug 30 '15
View all comments
Show parent comment
18
u/mozjag Aug 30 '15
If you look at the output of your code you'll notice the character in the bottom right of the maze is missing. If I change the
--itoi--I get that character in the bottom right and no line break before the first line.In both cases
igoes from 3999 downwards in the body of the for-loop since the decrement happens as part of the test and therefore before execution of the body, so you can't get into the situation where4000 % 80results in an empty line before the maze. The difference is that for--ithe new value ofiis tested for false-ness where fori--the old value is tested, so ifiis 1, in the--icase you test 0 for false-ness and skip the body, effectively looping from 3999 to 1 inclusive, where in thei--case you test 1 for false-ness and execute the body, effectively looping from 3999 to 0 inclusive.