In chapter 3 of Karel the Robot, I have learned that Karel uses Control Statements. In chapter 2, Karel simply followed commands in order. Some of these commands were separated in to methods so that a single command could be used to issue several commands from a block, but in essence, Karel would do in order what you told him to do.
Control Statements change things in that you can tell Karel to do something based on a condition of his surroundings or based on a loop so he can do something while something else is true… such as “move forwards if there is no wall ahead”.
Conditional Statements
Two types of control statements are introduced in chapter 3 of Karel the Robot. The first type are called Conditional Statements. These are coded by using what is called the if statement. What this means is that a certain part of the program will run “if” a condition holds true. That condition could be something like “if Karel has beepers in his bag, run this section of code”. When his beepers run out, the program will then stop or move on to the next part.
Example:
if (condition) {
statements put between the curly braces.
}