Decision Making

Read this chapter, which reviews how computers make decisions using if statements. As you read this tutorial, you will understand that sometimes it is important to evaluate the value of an expression and perform a task if the value comes out to be true and another task if it is false. In particular, try the simulated program under the heading "Simulated Program" to see how a different response is presented to the user based on if a number is positive or negative.

Pay special attention to the "More Than One Statement per Branch" header to learn how the 'else' statement is used when there is more than one choice.

1. Decision Making

lightning

This chapter looks at how computer programs make decisions using the if statement. This statement is one of the fundamental building blocks of programming.

Chapter Topics:

      • Two-way Decisions
      • The if statement
      • Outline of a two-way decision
      • Blocks of statements
      • Boolean Expressions
      • Relational Operators
      • Example Programs


Question 1:

You are driving in your car and it starts to rain. The rain falls on your windshield and makes
it hard to see. Should your windshield wipers be on or off?


Source: Bradley Kjell, http://programmedlessons.org/Java9/chap16/ch16_01.html
Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 License.