In this chapter, things get kicked up a notch and become really fun!
Conditional statements tell the computer to make a choice depending on the evaluation of a condition. Often, evaluating the condition means checking to see what the user selected—so conditional statements allow you to create programs that are interactive. What the computer does, in other words, depends on what the human interacting with the computer does.
Without conditional statements, it’s hard to use a computer as anything much more than a really good calculation engine—so conditionals are crucial to understanding the true potential of computer programs.
The last topic in this chapter is using the switch statement. Switch statements can be a powerful way to code multiple if statements as a single evaluative statement—thus greatly simplifying code, which is always a good thing.
I also show you how to recode the Rock, Scissors, and Paper game more simply, using two switch statements rather than the many if statements in the original version.
To accomplish the goals of this chapter, particularly creating the Rock, Scissors, and Paper game, we’ll have to get a little ahead of ourselves. Some of the code in this chapter uses conceptual material not explained in full detail until later in this book. Don’t be scared; I explain things as we go, and nothing in this chapter should give you great difficulty.