SlideShare a Scribd company logo
Control Flow Statements
Branching Statements
Looping Statements
Jump Statemetns
Branching Statements
• If statement
• If else Statement
• If..else…if statement
• Nest if…else statement
• Switch Statement
<<goTo first slide>>
If Statement
• An if statement consists of a Boolean expression followed by one or more
statements. If the Boolean expression evaluates to true then the block of
code inside the if statement will be executed. If not the first set of code
after the end of the if statement (after the closing curly brace) will be
executed.
if(Boolean expression)
{
//Some code should be work
}
public static void main(String[] y)
{
int my_int=25;
if(my_int==25)
{
System.out.println("the condition is true");
}
}
Go to branch statement slide
If else Statement
• An if statement can be followed by an optional else statement,
which executes when the Boolean expression is false.
if(Boolean expression)
{ //some code excut }
else
{ //some code excut }
public static void main(String[] y)
{
int my_int=25;
if(my_int<25)
{ System.out.println("the condition is true"); }
else
{ System.out.println("the condition is not true"); }
}
• Go to branch statement slide
If…else…if statement
• An if statement can be followed by an optional else if...else statement,
which is very useful to test various conditions using single if...else if
statement.
When using if , else if , else statements there are few points to keep in mind.
• An if can have zero or one else's and it must come after any else if's.
• An if can have zero to many else if's and they must come before the else.
• Once an else if succeeds, none of the remaining else if's or else's will be
tested.
if(Boolean Expression 1)
{ //some code }
else if (Boolean Expression 2)
{ //some code }
else if (Boolean Expression 2)
{ //some code }
else
{ //some code }
public static void main(String[] y)
{
int my_int=25;
if(my_int<25)
{
System.out.println("the condition is true");
}
else if(my_int>25)
{System.out.println("the else if condition is true for 25 >
25");
}
else if(my_int==25)
{
System.out.println("the condition is true for 25==25");
}
else
{
System.out.println("any of the condition is not ture");
}
}
Go to branch statement slides
Nest if…else Statement
• It is always legal to nest if-else statements which means you can use one if
or else if statement inside another if or else if statement.
if(boolean expression 1)
{
if(boolean expression 2)
{ //some code }
else
{ //some code }
}
public static void main(String[] y)
{
int course_value=90;
String course_name="java";
String Course_type="core & advanced";
if(course_value==90)
{
if(course_name=="java")
{
if(Course_type=="core & advanced")
{
System.out.println("the nested condition is
true");
}
}
}
else
{
System.out.println("the nested conditions are not true");
}
}
Go to Branch statement slide
Switch Statement
• Switch case statements are a substitute for long if statements that
compare a variable to several "integral" values.. The value of the variable
given into switch is compared to the value following each of the cases, and
when one value matches the value of the variable, the computer
continues executing the program from that point.
switch(expression)
{
case value1: {//some code}break;
case value2: {//some code}break;
default: {//some code}break;
}
public static void main(String[] y)
{
int x=10;
/*
* x value is compared with case values
*/
switch(x)
{
case 10:{System.out.println("the x value is 10");}break;
case 30:{System.out.println("the x value is 30");}break;
case 40:{System.out.println("the x value is 40");}break;
}
}
Go to branch statement slide
LOOP control Statements
• loop is a sequence of instruction s that is continually repeated until a
certain condition is reached.
There are four types of loops:
• For loop
• For each loop
• While loop
• Do..While loop
<<goto first slide>>
For loop
• The for is an entry-entrolled loop and is used when an action is to
repeated for a predetermined number of times
for(initial value; test condition; increment)
{ //some code }
public static void main(String[] y)
{
for(int i=0; i<5; i++)
{System.out.println("hello world "+i);}
}
Go to loop slide
Foreach Statement
• A ForEach style loop is designed to cycle through a collection of
objects,such as an array, in strictly sequential fashion, from start to
finish.Implement a foreach loop by using the keyword foreach, java adds
the foreach compability by enhancing the for statement.
• for(type itr-var:collection)statement-block
int[] a={1,2,3,4};
for(int x:a)
{
System.out.println("array of a["+x+"] "+a[x]);
}
Go to loop slide
While loop(Entry Control loop)
• It repeates a statement or block while its controlling expression(any boolean
Expression) is true
• The body of the loop will be executed as long as the conditional expression is
true.
while(condition)
{
//body of code
}
public static void main(String[] y)
{
while(x<5)
{ /*x++ increment value of x;*/
System.out.println("the value of x is "+x);
x++;
}
}
Go to loop slide
Do-while loop
• A while loop is initially false then the body of the loop will not be executed at
all .The do-while loop always executes its body at least once because its
conditional expression is at the bottom of the loop
do
{ //body of code
}while(boolean expression);
System.out.println("the do While loop");
int x=1;
do
{
/*x++ increment value of x;
*/
System.out.println("the value of x is "+x);
x++;
}while(x<5);
Go to loop slided
Jump Statements
• Break
• Continue
• Return
<<goto first slide>>
Jump Statements
• Break
• In java the break statement has 3 uses
• Terminates a statement sequence in a switch statement
• It can be used to exit loop
• It can be used more civilized form of goto statement
• Using Break to exit the loop
By using break, you can force immediate termination of a loop .when break
statement is encountered inside a loop the loop is terminated and
program control resumes at the next statement following loop
public static void main(String[] y)
{
for(int i=0;i<10;i++)
{
if(i==5)
{
System.out.println("condition break");
break;
}
System.out.println("the value of i is::"+i);
}
}
• Using break in the form of GOTO
• Syntax Break label_name;
public static void main(String[] y)
{
first:{
secound:{
third:{
System.out.println("third block");
if(true)
{
break secound;
}
}
System.out.println("secound block");
}
System.out.println("first block");
}
}
go to jump statements
Continue
• A continue statement causes control to be transferred directly to the
conditional expression that controls the loop
public static void main(String[] y)
{
for(int i=0;i<5;i++)
{
if(true)
{
System.out.println("the if block");
continue;
}
System.out.println("the for loop");
}
}
Using continue with labels
• Specify the labels with continue statement
public static void main(String[] y)
{
outer:for(int i=0;i<=2;i++){
for(int j=0;j<=1;j++)
{
System.out.println("value of J is::"+j);
continue outer;
}
System.out.println("the value of i is::"+i);
}
/*
for continue labels it should be used with loops only not for blocks
*/
}
Go to jump statements
Return
• The return statement is used to explicitly return from a method.That is,it
causes program control to transfer back to the caller of the method.At any
time in a method the return statement can be used to cause execution to
branch back to the caller of the method.Thus,the return statement can be
used to cause execution to branch back to the caller ot the method.Thus, the
return statement immediately terminates the method in which it is executed.
public static void main(String[] y)
{
System.out.println("before return statement");
if(true)
{
return;
}
System.out.println("after return statement");
/*
here return causes execution to return to the java run-time system
*/
}
class Demo_break
{
int demo()
{
return(1);
}
public static void main(String[] y)
{
Demo_break d=new Demo_break();
System.out.println("the return value
is"+d.demo());
}
}
• goto jump statement
• Find the errors in the following
1. If(x+y=z&&y>0)
2. If(x>0);
A=b+c;
Else
A=a*b;
3. If(x<0)||(q<0)
Class ifelse
{ int result=55; char grade;
if(result>90) grade=‘A’;
else if(result>80)grade=“B”;
else if(result>70) grade=“c”;
else grade=“F”;
else grade=“g”;
System.out.println(“the grade is “+grade);
}
See the output
• Correct the code to print the output “correct
value”
public static void main(String[] args) {
int i=2;
if(i=2)
{
System.out.println("correct value");
}
else
{
System.out.println("not correct value");
}
Control flow statements in java
Ad

More Related Content

What's hot (20)

Method overriding
Method overridingMethod overriding
Method overriding
Azaz Maverick
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
Farooq Baloch
 
I/O Streams
I/O StreamsI/O Streams
I/O Streams
Ravi Chythanya
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
VINOTH R
 
Wrapper class
Wrapper classWrapper class
Wrapper class
kamal kotecha
 
Polymorphism In Java
Polymorphism In JavaPolymorphism In Java
Polymorphism In Java
Spotle.ai
 
Java package
Java packageJava package
Java package
CS_GDRCST
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
Pooja Jaiswal
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
Indu Sharma Bhardwaj
 
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
Abhilash Nair
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
Madishetty Prathibha
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
Google
 
Static Members-Java.pptx
Static Members-Java.pptxStatic Members-Java.pptx
Static Members-Java.pptx
ADDAGIRIVENKATARAVIC
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
VINOTH R
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
VINOTH R
 
Inheritance in java
Inheritance in java Inheritance in java
Inheritance in java
yash jain
 
String, string builder, string buffer
String, string builder, string bufferString, string builder, string buffer
String, string builder, string buffer
SSN College of Engineering, Kalavakkam
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
Spotle.ai
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
Abhilash Nair
 

Viewers also liked (20)

Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
Raj Parekh
 
Strings Arrays
Strings ArraysStrings Arrays
Strings Arrays
phanleson
 
4.1 sequentioal search
4.1 sequentioal search4.1 sequentioal search
4.1 sequentioal search
Krish_ver2
 
Java SE 8
Java SE 8Java SE 8
Java SE 8
Murali Pachiyappan
 
Byte array to hex string transformer
Byte array to hex string transformerByte array to hex string transformer
Byte array to hex string transformer
Rahul Kumar
 
array
array array
array
Yaswanth Babu Gummadivelli
 
Break and continue statement in C
Break and continue statement in CBreak and continue statement in C
Break and continue statement in C
Innovative
 
5 2. string processing
5 2. string processing5 2. string processing
5 2. string processing
웅식 전
 
Design, Simulation and Verification of Generalized Photovoltaic cells Model U...
Design, Simulation and Verification of Generalized Photovoltaic cells Model U...Design, Simulation and Verification of Generalized Photovoltaic cells Model U...
Design, Simulation and Verification of Generalized Photovoltaic cells Model U...
IDES Editor
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
Danairat Thanabodithammachari
 
Switch case and looping statement
Switch case and looping statementSwitch case and looping statement
Switch case and looping statement
_jenica
 
algorithm
algorithmalgorithm
algorithm
kokilabe
 
TypeScript by Howard
TypeScript by HowardTypeScript by Howard
TypeScript by Howard
LearningTech
 
Multi string PV array
Multi string PV arrayMulti string PV array
Multi string PV array
NIT MEGHALAYA
 
10. switch case
10. switch case10. switch case
10. switch case
Way2itech
 
Java Programming - 03 java control flow
Java Programming - 03 java control flowJava Programming - 03 java control flow
Java Programming - 03 java control flow
Danairat Thanabodithammachari
 
java programming- control statements
 java programming- control statements java programming- control statements
java programming- control statements
jyoti_lakhani
 
Java 8 new features or the ones you might actually use
Java 8 new features or the ones you might actually useJava 8 new features or the ones you might actually use
Java 8 new features or the ones you might actually use
Sharon Rozinsky
 
Nomenclature of Organic Compounds (IUPAC)
Nomenclature of Organic Compounds (IUPAC)Nomenclature of Organic Compounds (IUPAC)
Nomenclature of Organic Compounds (IUPAC)
Lexter Supnet
 
Epics and User Stories
Epics and User StoriesEpics and User Stories
Epics and User Stories
Manish Agrawal, CSP®
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
Raj Parekh
 
Strings Arrays
Strings ArraysStrings Arrays
Strings Arrays
phanleson
 
4.1 sequentioal search
4.1 sequentioal search4.1 sequentioal search
4.1 sequentioal search
Krish_ver2
 
Byte array to hex string transformer
Byte array to hex string transformerByte array to hex string transformer
Byte array to hex string transformer
Rahul Kumar
 
Break and continue statement in C
Break and continue statement in CBreak and continue statement in C
Break and continue statement in C
Innovative
 
5 2. string processing
5 2. string processing5 2. string processing
5 2. string processing
웅식 전
 
Design, Simulation and Verification of Generalized Photovoltaic cells Model U...
Design, Simulation and Verification of Generalized Photovoltaic cells Model U...Design, Simulation and Verification of Generalized Photovoltaic cells Model U...
Design, Simulation and Verification of Generalized Photovoltaic cells Model U...
IDES Editor
 
Switch case and looping statement
Switch case and looping statementSwitch case and looping statement
Switch case and looping statement
_jenica
 
TypeScript by Howard
TypeScript by HowardTypeScript by Howard
TypeScript by Howard
LearningTech
 
Multi string PV array
Multi string PV arrayMulti string PV array
Multi string PV array
NIT MEGHALAYA
 
10. switch case
10. switch case10. switch case
10. switch case
Way2itech
 
java programming- control statements
 java programming- control statements java programming- control statements
java programming- control statements
jyoti_lakhani
 
Java 8 new features or the ones you might actually use
Java 8 new features or the ones you might actually useJava 8 new features or the ones you might actually use
Java 8 new features or the ones you might actually use
Sharon Rozinsky
 
Nomenclature of Organic Compounds (IUPAC)
Nomenclature of Organic Compounds (IUPAC)Nomenclature of Organic Compounds (IUPAC)
Nomenclature of Organic Compounds (IUPAC)
Lexter Supnet
 
Ad

Similar to Control flow statements in java (20)

Lecture - 5 Control Statement
Lecture - 5 Control StatementLecture - 5 Control Statement
Lecture - 5 Control Statement
manish kumar
 
Control statements
Control statementsControl statements
Control statements
raksharao
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
PRN USM
 
Java loops
Java loopsJava loops
Java loops
ricardovigan
 
Unit-02 Selection, Mathematical Functions and loops.pptx
Unit-02 Selection, Mathematical Functions and loops.pptxUnit-02 Selection, Mathematical Functions and loops.pptx
Unit-02 Selection, Mathematical Functions and loops.pptx
jessicafalcao1
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
jahanullah
 
Core java
Core javaCore java
Core java
Uday Sharma
 
Loops
LoopsLoops
Loops
Kamran
 
DAY_1.2.pptx
DAY_1.2.pptxDAY_1.2.pptx
DAY_1.2.pptx
ishasharma835109
 
130706266060138191
130706266060138191130706266060138191
130706266060138191
Tanzeel Ahmad
 
6_A1944859510_21789_2_2018_06. Branching Statements.ppt
6_A1944859510_21789_2_2018_06. Branching Statements.ppt6_A1944859510_21789_2_2018_06. Branching Statements.ppt
6_A1944859510_21789_2_2018_06. Branching Statements.ppt
RithwikRanjan
 
M C6java5
M C6java5M C6java5
M C6java5
mbruggen
 
07 flow control
07   flow control07   flow control
07 flow control
dhrubo kayal
 
Module 5 : Statements & Exceptions
Module 5 : Statements & ExceptionsModule 5 : Statements & Exceptions
Module 5 : Statements & Exceptions
Prem Kumar Badri
 
JPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingJPC#8 Introduction to Java Programming
JPC#8 Introduction to Java Programming
Pathomchon Sriwilairit
 
Programming in java - Concepts- Operators- Control statements-Expressions
Programming in java - Concepts- Operators- Control statements-ExpressionsProgramming in java - Concepts- Operators- Control statements-Expressions
Programming in java - Concepts- Operators- Control statements-Expressions
LovelitJose
 
Loop control statements
Loop control statementsLoop control statements
Loop control statements
Jaya Kumari
 
Unit- 1 -Java - Decision Making . pptx
Unit- 1 -Java - Decision  Making .  pptxUnit- 1 -Java - Decision  Making .  pptx
Unit- 1 -Java - Decision Making . pptx
CmDept
 
3-Decision making and Control structures-28-04-2023.pptx
3-Decision making and Control structures-28-04-2023.pptx3-Decision making and Control structures-28-04-2023.pptx
3-Decision making and Control structures-28-04-2023.pptx
SrikarPrasadDonavall
 
Java presentation
Java presentationJava presentation
Java presentation
Muhammad Saleem Nagri
 
Lecture - 5 Control Statement
Lecture - 5 Control StatementLecture - 5 Control Statement
Lecture - 5 Control Statement
manish kumar
 
Control statements
Control statementsControl statements
Control statements
raksharao
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
PRN USM
 
Unit-02 Selection, Mathematical Functions and loops.pptx
Unit-02 Selection, Mathematical Functions and loops.pptxUnit-02 Selection, Mathematical Functions and loops.pptx
Unit-02 Selection, Mathematical Functions and loops.pptx
jessicafalcao1
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
jahanullah
 
6_A1944859510_21789_2_2018_06. Branching Statements.ppt
6_A1944859510_21789_2_2018_06. Branching Statements.ppt6_A1944859510_21789_2_2018_06. Branching Statements.ppt
6_A1944859510_21789_2_2018_06. Branching Statements.ppt
RithwikRanjan
 
Module 5 : Statements & Exceptions
Module 5 : Statements & ExceptionsModule 5 : Statements & Exceptions
Module 5 : Statements & Exceptions
Prem Kumar Badri
 
JPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingJPC#8 Introduction to Java Programming
JPC#8 Introduction to Java Programming
Pathomchon Sriwilairit
 
Programming in java - Concepts- Operators- Control statements-Expressions
Programming in java - Concepts- Operators- Control statements-ExpressionsProgramming in java - Concepts- Operators- Control statements-Expressions
Programming in java - Concepts- Operators- Control statements-Expressions
LovelitJose
 
Loop control statements
Loop control statementsLoop control statements
Loop control statements
Jaya Kumari
 
Unit- 1 -Java - Decision Making . pptx
Unit- 1 -Java - Decision  Making .  pptxUnit- 1 -Java - Decision  Making .  pptx
Unit- 1 -Java - Decision Making . pptx
CmDept
 
3-Decision making and Control structures-28-04-2023.pptx
3-Decision making and Control structures-28-04-2023.pptx3-Decision making and Control structures-28-04-2023.pptx
3-Decision making and Control structures-28-04-2023.pptx
SrikarPrasadDonavall
 
Ad

More from yugandhar vadlamudi (15)

Toolbarexample
ToolbarexampleToolbarexample
Toolbarexample
yugandhar vadlamudi
 
Singleton pattern
Singleton patternSingleton pattern
Singleton pattern
yugandhar vadlamudi
 
Object Relational model for SQLIite in android
Object Relational model for SQLIite  in android Object Relational model for SQLIite  in android
Object Relational model for SQLIite in android
yugandhar vadlamudi
 
JButton in Java Swing example
JButton in Java Swing example JButton in Java Swing example
JButton in Java Swing example
yugandhar vadlamudi
 
Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
yugandhar vadlamudi
 
Packaes & interfaces
Packaes & interfacesPackaes & interfaces
Packaes & interfaces
yugandhar vadlamudi
 
Exception handling in java
Exception handling in java Exception handling in java
Exception handling in java
yugandhar vadlamudi
 
JMenu Creation in Java Swing
JMenu Creation in Java SwingJMenu Creation in Java Swing
JMenu Creation in Java Swing
yugandhar vadlamudi
 
Adding a action listener to button
Adding a action listener to buttonAdding a action listener to button
Adding a action listener to button
yugandhar vadlamudi
 
Dynamic method dispatch
Dynamic method dispatchDynamic method dispatch
Dynamic method dispatch
yugandhar vadlamudi
 
Operators in java
Operators in javaOperators in java
Operators in java
yugandhar vadlamudi
 
Inheritance
InheritanceInheritance
Inheritance
yugandhar vadlamudi
 
Closer look at classes
Closer look at classesCloser look at classes
Closer look at classes
yugandhar vadlamudi
 
java Applet Introduction
java Applet Introductionjava Applet Introduction
java Applet Introduction
yugandhar vadlamudi
 
Class introduction in java
Class introduction in javaClass introduction in java
Class introduction in java
yugandhar vadlamudi
 

Recently uploaded (20)

2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx
*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx
*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx
Arshad Shaikh
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx
*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx
*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx
Arshad Shaikh
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 

Control flow statements in java

  • 1. Control Flow Statements Branching Statements Looping Statements Jump Statemetns
  • 2. Branching Statements • If statement • If else Statement • If..else…if statement • Nest if…else statement • Switch Statement <<goTo first slide>>
  • 3. If Statement • An if statement consists of a Boolean expression followed by one or more statements. If the Boolean expression evaluates to true then the block of code inside the if statement will be executed. If not the first set of code after the end of the if statement (after the closing curly brace) will be executed. if(Boolean expression) { //Some code should be work } public static void main(String[] y) { int my_int=25; if(my_int==25) { System.out.println("the condition is true"); } } Go to branch statement slide
  • 4. If else Statement • An if statement can be followed by an optional else statement, which executes when the Boolean expression is false. if(Boolean expression) { //some code excut } else { //some code excut } public static void main(String[] y) { int my_int=25; if(my_int<25) { System.out.println("the condition is true"); } else { System.out.println("the condition is not true"); } } • Go to branch statement slide
  • 5. If…else…if statement • An if statement can be followed by an optional else if...else statement, which is very useful to test various conditions using single if...else if statement. When using if , else if , else statements there are few points to keep in mind. • An if can have zero or one else's and it must come after any else if's. • An if can have zero to many else if's and they must come before the else. • Once an else if succeeds, none of the remaining else if's or else's will be tested. if(Boolean Expression 1) { //some code } else if (Boolean Expression 2) { //some code } else if (Boolean Expression 2) { //some code } else { //some code }
  • 6. public static void main(String[] y) { int my_int=25; if(my_int<25) { System.out.println("the condition is true"); } else if(my_int>25) {System.out.println("the else if condition is true for 25 > 25"); } else if(my_int==25) { System.out.println("the condition is true for 25==25"); } else { System.out.println("any of the condition is not ture"); } } Go to branch statement slides
  • 7. Nest if…else Statement • It is always legal to nest if-else statements which means you can use one if or else if statement inside another if or else if statement. if(boolean expression 1) { if(boolean expression 2) { //some code } else { //some code } }
  • 8. public static void main(String[] y) { int course_value=90; String course_name="java"; String Course_type="core & advanced"; if(course_value==90) { if(course_name=="java") { if(Course_type=="core & advanced") { System.out.println("the nested condition is true"); } } } else { System.out.println("the nested conditions are not true"); } } Go to Branch statement slide
  • 9. Switch Statement • Switch case statements are a substitute for long if statements that compare a variable to several "integral" values.. The value of the variable given into switch is compared to the value following each of the cases, and when one value matches the value of the variable, the computer continues executing the program from that point. switch(expression) { case value1: {//some code}break; case value2: {//some code}break; default: {//some code}break; }
  • 10. public static void main(String[] y) { int x=10; /* * x value is compared with case values */ switch(x) { case 10:{System.out.println("the x value is 10");}break; case 30:{System.out.println("the x value is 30");}break; case 40:{System.out.println("the x value is 40");}break; } } Go to branch statement slide
  • 11. LOOP control Statements • loop is a sequence of instruction s that is continually repeated until a certain condition is reached. There are four types of loops: • For loop • For each loop • While loop • Do..While loop <<goto first slide>>
  • 12. For loop • The for is an entry-entrolled loop and is used when an action is to repeated for a predetermined number of times for(initial value; test condition; increment) { //some code } public static void main(String[] y) { for(int i=0; i<5; i++) {System.out.println("hello world "+i);} } Go to loop slide
  • 13. Foreach Statement • A ForEach style loop is designed to cycle through a collection of objects,such as an array, in strictly sequential fashion, from start to finish.Implement a foreach loop by using the keyword foreach, java adds the foreach compability by enhancing the for statement. • for(type itr-var:collection)statement-block int[] a={1,2,3,4}; for(int x:a) { System.out.println("array of a["+x+"] "+a[x]); } Go to loop slide
  • 14. While loop(Entry Control loop) • It repeates a statement or block while its controlling expression(any boolean Expression) is true • The body of the loop will be executed as long as the conditional expression is true. while(condition) { //body of code } public static void main(String[] y) { while(x<5) { /*x++ increment value of x;*/ System.out.println("the value of x is "+x); x++; } } Go to loop slide
  • 15. Do-while loop • A while loop is initially false then the body of the loop will not be executed at all .The do-while loop always executes its body at least once because its conditional expression is at the bottom of the loop do { //body of code }while(boolean expression); System.out.println("the do While loop"); int x=1; do { /*x++ increment value of x; */ System.out.println("the value of x is "+x); x++; }while(x<5); Go to loop slided
  • 16. Jump Statements • Break • Continue • Return <<goto first slide>>
  • 17. Jump Statements • Break • In java the break statement has 3 uses • Terminates a statement sequence in a switch statement • It can be used to exit loop • It can be used more civilized form of goto statement • Using Break to exit the loop By using break, you can force immediate termination of a loop .when break statement is encountered inside a loop the loop is terminated and program control resumes at the next statement following loop
  • 18. public static void main(String[] y) { for(int i=0;i<10;i++) { if(i==5) { System.out.println("condition break"); break; } System.out.println("the value of i is::"+i); } }
  • 19. • Using break in the form of GOTO • Syntax Break label_name; public static void main(String[] y) { first:{ secound:{ third:{ System.out.println("third block"); if(true) { break secound; } } System.out.println("secound block"); } System.out.println("first block"); } } go to jump statements
  • 20. Continue • A continue statement causes control to be transferred directly to the conditional expression that controls the loop public static void main(String[] y) { for(int i=0;i<5;i++) { if(true) { System.out.println("the if block"); continue; } System.out.println("the for loop"); } }
  • 21. Using continue with labels • Specify the labels with continue statement public static void main(String[] y) { outer:for(int i=0;i<=2;i++){ for(int j=0;j<=1;j++) { System.out.println("value of J is::"+j); continue outer; } System.out.println("the value of i is::"+i); } /* for continue labels it should be used with loops only not for blocks */ } Go to jump statements
  • 22. Return • The return statement is used to explicitly return from a method.That is,it causes program control to transfer back to the caller of the method.At any time in a method the return statement can be used to cause execution to branch back to the caller of the method.Thus,the return statement can be used to cause execution to branch back to the caller ot the method.Thus, the return statement immediately terminates the method in which it is executed. public static void main(String[] y) { System.out.println("before return statement"); if(true) { return; } System.out.println("after return statement"); /* here return causes execution to return to the java run-time system */ }
  • 23. class Demo_break { int demo() { return(1); } public static void main(String[] y) { Demo_break d=new Demo_break(); System.out.println("the return value is"+d.demo()); } } • goto jump statement
  • 24. • Find the errors in the following 1. If(x+y=z&&y>0) 2. If(x>0); A=b+c; Else A=a*b; 3. If(x<0)||(q<0)
  • 25. Class ifelse { int result=55; char grade; if(result>90) grade=‘A’; else if(result>80)grade=“B”; else if(result>70) grade=“c”; else grade=“F”; else grade=“g”; System.out.println(“the grade is “+grade); } See the output
  • 26. • Correct the code to print the output “correct value” public static void main(String[] args) { int i=2; if(i=2) { System.out.println("correct value"); } else { System.out.println("not correct value"); }
  翻译: