[Closed] skipping loop iterations
hi im trying to skip loop iterations in a for loop based on weather the value is a negative number or positive number (2,4,6,8,10…100) but i cant figure out any way of doing it. Does anybody have any ideas
calling ‘continue’ within a loop will cause it to skip the remainder of the code and continue to the next loop iteration
if (number < 0) do ( continue )
if you need to test a number to see whether it is even or odd, you can do this
for LOOP do
(
if mod number 2 > 0 do (continue) --the number is odd
)
And another one, skipping the if statement altogether:
for i = -50 to 100 where mod i 2 == 0 and i >= 0 do
(
print i
)
-Johan
well gosh… if you need that, then why not 1. start your loop positive, at an even number and 2. use the ‘by 2’ statement in the loop so that it will never hit an odd number to begin with?
I thought this was for a more generic problem
well alright… how about replacing ‘mod <number> 2 != 0’ with ‘bit.get <number> 1’?
What the heck does “returns the boolean state of the least significant bit” mean ?
The Least significant bit (LSB) is the last number in an binary digit.
1001011010100 has LSB 0
1001011010101 has LSB 1
Every binary with LSB 1 is odd.
So bit.get 3 1 is true, bit.get 2 1 is false.