[MUSIC]
[SOUND] The control flow
statements are statements that alter the order in which statements are executed and
which lines of code are executed.
So we've seen these before in C.
And these are common in every language.
We're gonna look at the if statement.
If then, if then else.
For loops.
And while loops.
So let's start with the if statement.
And this is pretty generic right here.
The template you can see up above.
If a condition is true, colon, you do some code.
That indented code block, that's all the code that you want to do,
you make sure it's indented right, so that the if statement, so the interpreter can
tell that it's supposed to be executed when the condition is true.
And then after the if statement is done, you have non-indented code.
And whatever non-indented code you have that signifies the if statement is done.
So, for instance, example.
If temp is greater than 80 it'll print it is hot.
There it'll print goodbye.
So, even if the temp isn't greater than 80, it'll still print goodbye.
Because the print goodbye is indented the same as the if which tells you,
okay the if statement is finished.
The print is not, the second print goodbye is not part of your statement.
It ends the if statement over before it..
So the indentation, again, is key here.
And, it is hot is printed if it's over 80.
So this is an if statement, you've seen this type of thing before.
If-else statements.
This is a very similar thing, an if condition but you add an else.
Now you have else: and you have another statement or a set of statements.
So this case I'm using a single statement in each path.
it temp is greater than 80 print hot.
Else print not hot.
Notice the print hot is indented,
the print not hot is indented, the print hot is indented under the if.
The print not hot is indented under the else.
And then print goodbye is not indented so
it means that the statement is done and it happens regardless of the condition.