preview

Decision Making : Learning Objectives And Outcomes

Satisfactory Essays

LESSON 2: DECISION MAKING
LEARNING OBJECTIVES AND OUTCOMES
• Introduction
• If statement
• Switch statement
• The While Statement
• The Do Statement
• The For Statement
INTRODUCTION
A set of statements in Java program are normally executed sequentially in the order of their appearance. However, in practice there are number of instances and conditions when we have to change the order of execution of statements. This involves certain type of decision-making to check whether the particular condition has occurred or not. Decision- making statements changes the flow of program based on those conditions.
Java possesses following decision-making statements:
1. If statement
2. Switch statement
3. Conditional operator statement

THE IF STATEMENT
In programming executing code when one condition happens rather than something else is very common. To control the flow of statements in such conditions, developers introduced if statement. If Statement in JAVA has following structure: if ( testing statement )
{
}
If statement is written in lowercase and test statement is mentioned inside round brackets. A pair of curly brackets is used to section off a chunk of code that we only want to execute if the test condition is satisfied. Some examples of decision making- if statements are as follows:
• If (total marks is less than 50) fail • If (door is open) enter • If (percentage is more than 75)
Permitted
• If (code is 0)
Switch is off
There are different forms of implementing if statement

Get Access