if - else - structure

Program branches on the basis of certain conditions belong to the basis structure of every program language. The instructions following if are only conducted it the condition is fullfilled. Othewise the instructions following else will be conducted.

In the first example 20 steps are drawn. Each uneven steps shall be drawn in red, each even step in green. If the number i is even or uneven can be proven with the modulo division by 2. If the result of the modulo division is 0 (i % 2 == 0), the number is even, otherwise it is uneven.

Additionally to the calculating operation +, -, * and / when programming, mostly the so called Modulo-Division % is used. This gives the rest out of the whole number division.
Conditions are indicated with the aid of comparing operations:
>, >= , < , <= , == , !=
Attention: equality operator == is always written with two equality signs

i = i + 10: after each loop cycle i is aumented by 10 j
In short you may also just write i += 10

setPos(0, 200)

The turtle starts drawing each line on the point (0, 200)

moveTo(i, -200)

Moves the turtle from the current position to the point with the coordinates (i, -200), whereat i can accept values (-200, -190. -180.... 200).

Multiple selection

Also multiple conditions can be proven consecutively. In our example, initially the pen colour is red, then green and for the last square yellow. The method fill() fills with the pen colour the closed area in which the turtle is.