P1 Exercise 3 - Conditional¶
Conditionals are all about making decisions in your robot’s code. Conditional statements, such as “if this is true then …”
usually evaluate an expression, such as “if this task is finished, then …” or in short this_task == finished
. Or you could
evaluate something numerical, such as nr_of_tasks_done < nr_of_all_tasks
(read: number of tasks done is smaller than the
number of all the tasks). So at the end of the day, all a conditional statement cares about is whether the expression evaluates
to true
or false
. Figure 3 shows an example where given a boolean variable, the conditional ends up rotating
the robot right or left.