[go: up one dir, main page]

0% found this document useful (0 votes)
10 views24 pages

Lecture 7

The document outlines a syllabus for a Java Programming course, focusing on the principles of Object-Oriented Programming and control statements. It covers various types of control statements in Java, including if, if-else, nested if, if-else-if ladder, switch-case, and jump statements. The document also provides syntax examples and objectives for understanding inheritance in Java.

Uploaded by

Deepak Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views24 pages

Lecture 7

The document outlines a syllabus for a Java Programming course, focusing on the principles of Object-Oriented Programming and control statements. It covers various types of control statements in Java, including if, if-else, nested if, if-else-if ladder, switch-case, and jump statements. The document also provides syntax examples and objectives for understanding inheritance in Java.

Uploaded by

Deepak Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

UNIVERSITY INSTITUTE COMPUTING

BSc (CS)/ BCA


Subject Name: Java Programming
Code: 22SCT-351/22CAT-351

JAVA PROGRAMMING DISCOVER . LEARN . EMPOWER


1
Syllabus

Unit-I
Principles of Object-Oriented Programming

• Introduction: Introduction to Java, Basic Features, JVM Concepts, A Simple Java


Program, Primitive Data Type and Variables, Java Keywords,.

2
Content

(Unit I)
Data Types
Chapter 1.2:
Lecture 1.2.3-
1. Java Control Statement
2. Types of Control Statement

3
Objectives/Outcomes

CO1: Identify the ways to implement the inheritance concept in


the Java programming language.

4
Control Statement

• In programming also we face some situations where we want a certain block of


code to be executed when some condition is fulfilled.
• A programming language uses control statements to control the flow of execution
of program based on certain conditions.
• These are used to cause the flow of execution to advance and branch based on
changes to the state of a program.

5
Types of Control Statement
Types of control / decision making statements in Java:
1. If
2. If-else
3. Nested-if
4. If-else-if ladder
5. Switch-case
6. Jump – break, continue, return

6
If Statement
• if statement is the most simple decision making statement. It is used to decide
whether a certain statement or block of statements will be executed or not i.e. if a
certain condition is true then a block of statement is executed otherwise not.

• SYNTAX
if(condition)
{
//statements to be executed if the condition is true
}

Fig 1: If Statement[1]

7
Example of ‘if’ statement

8
If-else Statement
• We can use the else statement with if statement to execute a block of code when the
condition is false.

• SYNTAX
if(condition)
{
//execute if the condition is true
}
else
{
//execute if the condition is false
}
Fig 2: If –else Statement[2]

9
Example of ‘if-else’ statement

10
Nested if
• Nested if statements means an if statement inside an if statement.

• SYNTAX
if(condition1)
{
//execute if the condition1 is true
}
if(condition2)
{
//execute if the condition is false
}

Fig 3: Nested If Statement[3]

11
Example of ‘nested-if’

12
4. if-else-if ladder
• Here, a user can decide among multiple options.
• SYNTAX
if(condition) {
statement;
}
else-if(condition) {
statement;
}
else {
statement;
}
Fig 4: If –else-if Statement

13
Example of ‘if-else-if’

14
Switch case
• The switch statement is a multi-way branch statement. It provides an easy way to
dispatch execution to different parts of code based on the value of the expression.
Syntax:
switch (expression) {
case value1:
statement1;
break;
case value2: statement2;
break;
.
default:
statement
Default;
} Fig 5: Switch Statement[5]

15
Example of ‘switch case’

16
Jump statement
Java supports three jump statement: break, continue and return. These three
statements transfer control to other part of the program.
(a) BREAK
In Java, break is majorly used for:
Terminate a sequence in a switch statement (discussed above).
To exit a loop.
Used as a “civilized” form of goto.

Fig 6: Break Statement[6]


17
Example of ‘break’

18
Jump statement contd.
(b) CONTINUE
Sometimes it is useful to force an early
iteration of a loop. That is, you might
want to continue running the loop but
stop processing the remainder of the code
in its body for this particular iteration.
This is, in effect, a goto just past the body
of the loop, to the loop’s end. The
continue statement performs such an
action.

Fig 7: Continue Statement[7]

19
Example of ‘continue’

20
Jump statement contd.
(c) RETURN
The return statement is used to
explicitly return from a method.
That is, it causes a program
control to transfer back to the
caller of the method.

21
References
• Fig 1:https://www.geeksforgeeks.org/decision-making-javaif
-else-switch-break-continue-jump/
• Fig 2:
https://www.geeksforgeeks.org/decision-making-javaif-else-switch-break-continue-jump/
• Fig 3:
https://www.geeksforgeeks.org/decision-making-javaif-else-switch-break-continue-jump/
• Fig 4:
https://www.geeksforgeeks.org/decision-making-javaif-else-switch-break-continue-jump/
• Fig 5:
https://www.geeksforgeeks.org/decision-making-javaif-else-switch-break-continue-jump/
• Fig 6:
https://www.geeksforgeeks.org/decision-making-javaif-else-switch-break-continue-jump/
• Fig 7:
https://www.geeksforgeeks.org/decision-making-javaif-else-switch-break-continue-jump/
22
References
• https://www.geeksforgeeks.org/decision-making-javaif-else-switch-break-continue-ju
mp/
• https://www.w3schools.com/java/java_conditions.asp

23
THANK YOU

24

You might also like