I need to check a variable if it is even or odd and I don't know how to do it in Imagine Logo.
In case that it is not possible, I need at least something like this...
if (a = 1 || a = 2 || a = 3)
I need to check a variable if it is even or odd and I don't know how to do it in Imagine Logo.
In case that it is not possible, I need at least something like this...
if (a = 1 || a = 2 || a = 3)
Copyright © 2021 Jogjafile Inc.
Typically this is done by using something that finds the remainder after a division. Even numbers divided by 2 will have a remainder of 0. Odd numbers divided by 2 will have a remainder of 1. If your numbers are negative you might have to pay attention to how the remainder is given back.
I don't know about Imagine Logo specifically, but this online interpreter for "a Logo" has three ways to say it (under the "Reference" link):
Assuming you have these available, then if you want to test if negative numbers are odd or even, it will be easier if you use
remainderor%instead ofmodulo. So for even:And for odd:
You may or may not want to look at the Wikipedia page for "Modulo operation".