In Lesson 21, the side scroller game, the answer key shows and If Statement inside of another If Statement. That was never explained in the lessons. Can someone explain that?
Hi @kbreitbach,
That is called a nested if statement. You would read it the same as a regular if statement but now you have more than one boolean expression or question. So, if the first if statement is true, then you look and evaluate the if statement inside. If the first if statement is false, you move to the next line of code.
In the code above from the side scroller, if the frog’s y position is more than 324 or near the bottom, then you evaluate if the up key is pressed to change the velocity. The frog’s y position must be greater than 324 before you evaluate if the up key is pressed.
Hope that helps,
~Michelle
1 Like