p5: conditionals / if statements

A condition like if( myVariable == true) or if(myVariable > 20) must always return a boolean value (true or false).

To construct more complex conditions for both if statements and loops we have to get into Boolean operators.

For our purposes == and === are equivalent. In javascript they compare both value and type of a variable.

Exercise

Starting fromĀ  a 9×9 pattern of green circles

https://openprocessing.org/sketch/1113894

MAKE A FORK FOR EACH EXERCISE BELOW

Reproduce the following outputs by changing only the if condition.
Can you make the condition as short as possible?

The quickest way to resolve this is with the modulo operator aka the remainder of the division. A column is in position 0, 2, 4, etc when the position is an even number therefore….