This lesson demonstrates how conditionals can be used to tailor a program to specific information. We don’t always have all of the information we need when writing a program. Sometimes you will want to do something different in one situation than in another, even if you don't know what situation will be true when your code runs. That is where conditionals come in. Conditionals allow a computer to make a decision, based on the information that is true any time your code is run.
One of the best parts of teaching conditionals is that students already understand the concept from their everyday lives. This lesson merges computer science into the real world by building off of their ability to tell if a condition is true or false. Students will learn to use
if statements to declare when a certain command should be run, as well as
if / else statements to declare when a command should be run and what do run otherwise. Students may not recognize the word conditionals, but most students will understand the idea of using "if" to make sure that some action only occurs when it is supposed to.
Students will be able to:
- define circumstances when certain parts of a program should run and when they shouldn't.
- determine whether a conditional is met based on criteria.
- traverse a program and predict the outcome, given a set of input.
Note: You will need to create a free account on code.org before you can view this resource.