MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/2yfew0/things_every_javascript_developer_should_know/cp9tfdk/?context=3
r/javascript • u/arcxyz • Mar 09 '15
118 comments sorted by
View all comments
1
I'm not quite understanding
while (i--){ ..... }
So when i equals zero, the loop breaks because 0 is sort of equal to false? Is this a safe solution?
1 u/ambalbemuth Mar 10 '15 As long as i isn't modified anywhere else and starts being an integer > 0, why wouldn't it? 1 u/kyrul Mar 10 '15 I think the only way it'd be unsafe is if multiple things were modifying i, such that it could decrement to a negative number in the span of the loop
As long as i isn't modified anywhere else and starts being an integer > 0, why wouldn't it?
I think the only way it'd be unsafe is if multiple things were modifying i, such that it could decrement to a negative number in the span of the loop
1
u/back-stabbath Mar 10 '15
I'm not quite understanding
while (i--){ ..... }
So when i equals zero, the loop breaks because 0 is sort of equal to false? Is this a safe solution?