Statement
Statements are instructions that we can get the computer to perform. Now that we have added control flow statements to our tool kit we have a whole range of different things we can get the computer to do.
Hopefully these seem like very simple actions, and you may even be thinking “Surely programs are made of more complex things?“. The answer is no! Individual instructions are very simple. Once you know how they work, you need to practice combining them in different ways to help achieve your goals.
Statements — when, why, and how?
We have already seen that a program is just a list of statements, as is a compound statement. If, case, while, do while, and for loop statements also contain statements, which are only run under certain conditions.
The great thing to see now is that you can combine these in lots of different ways. An if
statement can contain a while
loop, that contains a case
statement. Anywhere you can put a statement, you can now choose between any of these different statements to create a sequence of actions that get the computer to do what you want.