Conditional construction
The robot can use sensors not only in a cyclic design, but also without it. Before each action, the robot can check what the sensors show.
For this, a conditional construction
(if
) is used, which allows you to execute commands depending on the condition.
if (boolean condition)
{
commands that are executed if the condition is true (true)
}
otherwise
{
commands that are executed if the condition is false (false)
}
If you put the word not
(a logical connective meaning negation) before the condition, then the result "true" happens if the condition itself is false.