Académique Documents
Professionnel Documents
Culture Documents
UNIT
6.3
PROGRAMMING LANGUAGE (JAVA)
Control Statements - Presentation 1
Control Statements
Presentation 1
6.3-1
Fundamentals of Programming
Slide 1
Presentation 1
Slide 2
Revision
Answers
1. The eight basic primitive data types byte, short, int, long, float, double,
char and Boolean.
2. Variable is the name given to the memory location where a value is
stored.
3. The five keywords used in Java are, class, byte, int, long and float.
4. The two types of Typecasting are Implicit and Explicit conversion.
5. An operator is a symbol that instructs Java compiler to perform an
operation, or action. Operators are used to compute, compare values,
and test logical conditions.
Control Statements
Presentation 1
6.3-2
Fundamentals of Programming
Numerical Expressions
Assignment Expressions
Logical Expression
Slide 3
Objectives
At the end of this presentation, you will be able to:
Define branching statements and list their types
Define looping statements and list their types
Describe the structure and working of simple if
statements
Describe the structure and working of nested if
statements
Describe the structure and working of switch
statements
Start the class by explaining to the students that they will be learning about
the various branching and looping statements supported by Java.
Control Statements
Presentation 1
6.3-3
Fundamentals of Programming
Slide 4
Branching statement
Looping statement
Teaching Tip
Tell the students that in day-to-day life, decisions are made based on certain
condition and certain actions are performed. Give some examples of real-time
decisions. For example, if you miss the bus, you go by taxi.
Here the decision to go by taxi is taken if the bus is missed (condition). Ask
the students to state some similar examples.
Similarly, in programs, control statements are used to execute some
statements based on a condition.
Slide 5
Branching Statements
Control Statements
Presentation 1
6.3-4
Fundamentals of Programming
Ask the students to perform the Self-Check Exercise 6.3.1 given in the
Student Module.
Slide 6
Single if Statement
Before explaining the single if statement, ask the students to perform the SelfCheck Exercise 6.3.1 given in the Student Module.
Teaching Tip
Explain the single if statement with the following example.
If (miss the bus)
{
take a taxi;
}
Explain the best programming practice given under the single if statement
Control Statements
Presentation 1
6.3-5
Fundamentals of Programming
Slide 7
Hands-On!
Hands-On!
Control Statements
Presentation 1
6.3-6
Fundamentals of Programming
Slide 9
Syntax
if (<condition>)
{
<Conditional statements1>;
}
else
{
<Conditional statements2>;
}
Teaching Tip
Explain if-else with the following example.
if(miss bus)
{
go by taxi
}
else
{
go by bus
}
Here if you miss the bus, the decision is to go by taxi. Otherwise you can go
by bus itself.
Explain the Best programming practice for if-else given for Student
Module.
Explain the Note for if-else given for Student Module.
Control Statements
Presentation 1
6.3-7
Fundamentals of Programming
Slide 10
Hands-On!
Activity 6.3.1
Step 1: Open the data file InpSample.java.
Step 2: Run and observe the output.
Step 3: Draw the appropriate flowchart for the
program.
Control Statements
Presentation 1
6.3-8
Fundamentals of Programming
Slide 12
Lab Exercise
1.
Control Statements
Presentation 1
6.3-9
Fundamentals of Programming
Slide 13
Lab Exercise
2.
Slide 14
Lab Exercise
3.
Control Statements
Presentation 1
6.3-10
Fundamentals of Programming
Slide 15
Nested if Statement
Inner if
condition
Outer if
condition
Teaching Tip
In the example given in the slide, there are two if conditions, inner if and outer
if condition. The control moves to the inner if, when Condition 1 is satisfied.
When Condition 1 is not satisfied, Conditional statements 3 are executed.
Explain the Note for Nested if statement given Student Module.
Slide 16
Hands-On!
Control Statements
Presentation 1
6.3-11
Fundamentals of Programming
Slide 17
Lab Exercise 4
Slide 18
Lab Exercise
5.
Example
z
Refer to the solution for Lab Exercise in the Teacher Module.
Control Statements
Presentation 1
6.3-12
Fundamentals of Programming
Slide 19
Teaching Tip
Tell the students that an integer or a character constant follows the keyword
case. Based on the value returned from the expression in the switch, the
control is passed to the respective matching case.
Explain the Note for the break and switch statement given in the Student
Module.
Slide 20
Hands-On!
Control Statements
Presentation 1
6.3-13
Fundamentals of Programming
Slide 21
Hands-On!
Slide 22
Lab Exercise
6.
Example
1 Sunday
5 Thursday
Control Statements
Presentation 1
6.3-14
Fundamentals of Programming
Slide 23
Summary
In this presentation, you learnt the following:
Control statements are used to change the
sequential flow of a program.
The two types of control statements are
branching statements and looping statements.
Branching statements are used to evaluate
expressions and direct the program execution
based on the result.
In Java, the branching statements include if
and switch statements.
Slide 24
Assignment
1. Write short notes on control statements.
Answer
1. Control statements are used to change the sequential flow of a
program. Java supports two types of control statements. They are used
to alter the flow of the program.
Branching statement
Looping statement
Control Statements
Presentation 1
6.3-15