To get the full benefit of the lesson, watch the video
Lesson 11: Introduction to the if statement
NOTE: for a fast copy, follow these steps in order:
- Click anywhere in a text box below (result will be a blinking vertical line in the text box)
- Hit ctrl + A on the key board (the "ctrl + A" means hit Ctrl and A at the same time)
(The result should be that all the text inside the text box lights up in blue)
- Hit Ctrl + C (Nothing significantly happens that is visible) and now its copied to the clipboard and your ready to paste it anywhere
you wish
The if statement will only take bool parameter (value inside the paranthesis).
The if statement will either skip or execute the following program statement depending on the boolean value of the if statement.
Run both of these pieces of code. refer to the video for the detailed explanation.
the if statement can also refer to code blocks (code inside curly braces) to skip multiple lines of code.
you can input variables into th if parameter.
You can also put in int, double, char, etc types but don't forget the rules of the boolean values that aren't true or false.
Here are slightly more practical examples that might help you see why if statements are useful