David Freed wrote:It was my stupid misunderstanding, I thought in every line of a while , the while checks for the condition, whereas it just checks the condition in the whle(condition) line, tha's it.
Not stupid at all...If I said "keep repeating these steps while the light is green: turn around, jump, clap your hands, and sing a song", if you were in the middle of the song and the light turned purple, you'd probably stop singing right away. If you just finished turning and saw the purple light, you wouldn't jump or clap...You'd stop as soon as you noticed.
I can see why you'd think a program would work that way...but it doesn't. Look at it this way - now you know, and you'll never forget again.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors