3 ms·
You actually want: while x > 10 do x -= 10 while x < 0 do x += 10 while y > 10 do y -= 10 while y < 0 do y += 10 What you have will discard
by munificent 3y ago
You actually want:
while x > 10 do x -= 10
while x < 0 do x += 10
while y > 10 do y -= 10
while y < 0 do y += 10
What you have will discard some position information every time it wraps. Also, it won't correctly handle changes in position per frame that are larger than 10.
- kleer001 3y agoWell, yes, but I also need to take account of velocity and rotation too. I don't see that particular flow in the manual, and of course everything should be FULLCAPS. https://en.wikibooks.org/wiki/QBasic/Full_Book_View#DO_.._LOOP https://en.wikibooks.org/wiki/QBasic/Full_Book_View#DO_.._LO...
- notfish 3y agoOr just x = x mod 10 y = y mod 10
- munificent 3y agoThat depends on how the programming language implements modulo. Some don't wrap around the way you would need here when the dividend is negative. See: https://en.wikipedia.org/wiki/Modulo#Variants_of_the_definition https://en.wikipedia.org/wiki/Modulo#Variants_of_the_definit...
- ithkuil 3y agoWould this work in both flavours of the modulo operator? x = ((x mod 10) + 10) mod 10