SlideShare a Scribd company logo
1 of 14
CREATING CONDITION
Chapter 4.1:
3 Types Flow of Control
ï‚ž Sequential (we had learn in previous topic)
ï‚— The statements in a program are executed
in sequential order
ï‚ž Selection
ï‚— allow the program to select one of multiple
paths of execution.
ï‚— The path is selected based on some
conditional criteria (boolean expression)
ï‚ž Repetition (we will learn in next topic)
Flow of Control: Sequential
Structures
statement1
statement2
statement3
Flow of Control: Selection
Structures
ï‚ž If the boolean expression evaluates to true, the
statement will be executed. Otherwise, it will be
skipped.
Flow of Control: Selection
Structures
ï‚ž There are 3 types of Java selection
structures:
ï‚— if statement
ï‚— if-else statement
ï‚— switch statement
The if Statement
ï‚ž The if statement has the following syntax:
if ( condition )
statement;
if is a Java
reserved word
The condition must be a
boolean expression. It must
evaluate to either true or false.
If the condition is true, the statement is executed.
If it is false, the statement is skipped.
Logic of an if statement
condition
evaluated
statement
true
false
if Statement
if (amount <= balance)
balance = balance - amount;
Boolean Expressions
ï‚ž A condition often uses one of Java's
equality operators or relational
operators, which all return boolean
results:
== equal to
!= not equal to
< less than
> greater than
<= less than or equal to
>= greater than or equal to
The if Statement
if (total > MAX)
charge = total * MAX_RATE;
System.out.println ("The charge is " + charge);
ï‚ž First the condition is evaluated -- the value of total
is either greater than the value of MAX
ï‚ž If the condition is true, the assignment statement is
executed -- if it isn’t, it is skipped.
ï‚ž Either way, the call to println is executed next
Java code example
class Count
{
public static void main (String args[])
{
double y=15.0;
double x=25.0;
if (y!=x)
System.out.println("Result : y not equal
x");
}
}
Output
Result : y not equal x
Block Statements
ï‚ž Several statements can be grouped together into a
block statement delimited by braces
if (total > MAX)
{
System.out.println ("Error!!");
errorCount++;
}
Block Statements
if (amount <= balance)
{
balance = balance - amount;
System.out.println(“Acct new balance = “ +
balance);
}
COMPARE WITH
if (amount <= balance)
balance = balance - amount;
System.out.println(“Acct new balance = “ + balance);

More Related Content

What's hot

Conditional statement
Conditional statementConditional statement
Conditional statementMaxie Santos
 
Control statements in java
Control statements in javaControl statements in java
Control statements in javaManojkumar C
 
java programming- control statements
 java programming- control statements java programming- control statements
java programming- control statementsjyoti_lakhani
 
Java loops for, while and do...while
Java loops   for, while and do...whileJava loops   for, while and do...while
Java loops for, while and do...whileJayfee Ramos
 
If and select statement
If and select statementIf and select statement
If and select statementRahul Sharma
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsIt Academy
 
OCA JAVA - 2 Programming with Java Statements
 OCA JAVA - 2 Programming with Java Statements OCA JAVA - 2 Programming with Java Statements
OCA JAVA - 2 Programming with Java StatementsFernando Gil
 
Vb decision making statements
Vb decision making statementsVb decision making statements
Vb decision making statementspragya ratan
 
Selection statements
Selection statementsSelection statements
Selection statementsHarsh Dabas
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selectionOnline
 
"A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm ""A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm "CHANDAN KUMAR
 
M C6java6
M C6java6M C6java6
M C6java6mbruggen
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__elseeShikshak
 
Decision statements in vb.net
Decision statements in vb.netDecision statements in vb.net
Decision statements in vb.netilakkiya
 
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 statementRaj Parekh
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branchingHossain Md Shakhawat
 
Java if else condition - powerpoint persentation
Java if else condition - powerpoint persentationJava if else condition - powerpoint persentation
Java if else condition - powerpoint persentationManeesha Caldera
 
2.decision making
2.decision making2.decision making
2.decision makingHardik gupta
 

What's hot (20)

Conditional statement
Conditional statementConditional statement
Conditional statement
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
java programming- control statements
 java programming- control statements java programming- control statements
java programming- control statements
 
Java loops for, while and do...while
Java loops   for, while and do...whileJava loops   for, while and do...while
Java loops for, while and do...while
 
If and select statement
If and select statementIf and select statement
If and select statement
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java Statements
 
OCA JAVA - 2 Programming with Java Statements
 OCA JAVA - 2 Programming with Java Statements OCA JAVA - 2 Programming with Java Statements
OCA JAVA - 2 Programming with Java Statements
 
Vb decision making statements
Vb decision making statementsVb decision making statements
Vb decision making statements
 
Selection statements
Selection statementsSelection statements
Selection statements
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selection
 
If-else and switch-case
If-else and switch-caseIf-else and switch-case
If-else and switch-case
 
"A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm ""A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm "
 
M C6java6
M C6java6M C6java6
M C6java6
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
 
Decision statements in vb.net
Decision statements in vb.netDecision statements in vb.net
Decision statements in vb.net
 
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
 
Control Structures: Part 1
Control Structures: Part 1Control Structures: Part 1
Control Structures: Part 1
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Java if else condition - powerpoint persentation
Java if else condition - powerpoint persentationJava if else condition - powerpoint persentation
Java if else condition - powerpoint persentation
 
2.decision making
2.decision making2.decision making
2.decision making
 

Viewers also liked

Chapter 7.1
Chapter 7.1Chapter 7.1
Chapter 7.1sotlsoc
 
Chapter 5.3
Chapter 5.3Chapter 5.3
Chapter 5.3sotlsoc
 
Chapter 2.4
Chapter 2.4Chapter 2.4
Chapter 2.4sotlsoc
 
Chapter 7.3
Chapter 7.3Chapter 7.3
Chapter 7.3sotlsoc
 
Chapter 3.0 new
Chapter 3.0 newChapter 3.0 new
Chapter 3.0 newsotlsoc
 
Chapter 4.4
Chapter 4.4Chapter 4.4
Chapter 4.4sotlsoc
 
Chapter 7.0
Chapter 7.0 Chapter 7.0
Chapter 7.0 sotlsoc
 
Chapter 6.5 new
Chapter 6.5 newChapter 6.5 new
Chapter 6.5 newsotlsoc
 
Chapter 11.0
Chapter 11.0Chapter 11.0
Chapter 11.0sotlsoc
 
Chapter 6.2
Chapter 6.2Chapter 6.2
Chapter 6.2sotlsoc
 
Chapter 3.3
Chapter 3.3Chapter 3.3
Chapter 3.3sotlsoc
 
Chapter 8.3
Chapter 8.3Chapter 8.3
Chapter 8.3sotlsoc
 
Chapter 6.4
Chapter 6.4Chapter 6.4
Chapter 6.4sotlsoc
 
Chapter 5.2
Chapter 5.2Chapter 5.2
Chapter 5.2sotlsoc
 
Chapter 10.0
Chapter 10.0Chapter 10.0
Chapter 10.0sotlsoc
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1sotlsoc
 
Chapter 1.1
Chapter 1.1Chapter 1.1
Chapter 1.1sotlsoc
 
Chapter 2.0 new
Chapter 2.0 newChapter 2.0 new
Chapter 2.0 newsotlsoc
 
Chapter 6.5
Chapter 6.5Chapter 6.5
Chapter 6.5sotlsoc
 

Viewers also liked (19)

Chapter 7.1
Chapter 7.1Chapter 7.1
Chapter 7.1
 
Chapter 5.3
Chapter 5.3Chapter 5.3
Chapter 5.3
 
Chapter 2.4
Chapter 2.4Chapter 2.4
Chapter 2.4
 
Chapter 7.3
Chapter 7.3Chapter 7.3
Chapter 7.3
 
Chapter 3.0 new
Chapter 3.0 newChapter 3.0 new
Chapter 3.0 new
 
Chapter 4.4
Chapter 4.4Chapter 4.4
Chapter 4.4
 
Chapter 7.0
Chapter 7.0 Chapter 7.0
Chapter 7.0
 
Chapter 6.5 new
Chapter 6.5 newChapter 6.5 new
Chapter 6.5 new
 
Chapter 11.0
Chapter 11.0Chapter 11.0
Chapter 11.0
 
Chapter 6.2
Chapter 6.2Chapter 6.2
Chapter 6.2
 
Chapter 3.3
Chapter 3.3Chapter 3.3
Chapter 3.3
 
Chapter 8.3
Chapter 8.3Chapter 8.3
Chapter 8.3
 
Chapter 6.4
Chapter 6.4Chapter 6.4
Chapter 6.4
 
Chapter 5.2
Chapter 5.2Chapter 5.2
Chapter 5.2
 
Chapter 10.0
Chapter 10.0Chapter 10.0
Chapter 10.0
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1
 
Chapter 1.1
Chapter 1.1Chapter 1.1
Chapter 1.1
 
Chapter 2.0 new
Chapter 2.0 newChapter 2.0 new
Chapter 2.0 new
 
Chapter 6.5
Chapter 6.5Chapter 6.5
Chapter 6.5
 

Similar to Chapter 4.1

Selection Control Structures
Selection Control StructuresSelection Control Structures
Selection Control StructuresPRN USM
 
Chapter 4.2
Chapter 4.2Chapter 4.2
Chapter 4.2sotlsoc
 
Java input Scanner
Java input Scanner Java input Scanner
Java input Scanner Huda Alameen
 
03a control structures
03a   control structures03a   control structures
03a control structuresManzoor ALam
 
Chapter 4.3
Chapter 4.3Chapter 4.3
Chapter 4.3sotlsoc
 
slides03.ppt
slides03.pptslides03.ppt
slides03.pptAnjali127411
 
Ap Power Point Chpt3
Ap Power Point Chpt3Ap Power Point Chpt3
Ap Power Point Chpt3dplunkett
 
Ap Power Point Chpt3 B
Ap Power Point Chpt3 BAp Power Point Chpt3 B
Ap Power Point Chpt3 Bdplunkett
 
Control statements
Control statementsControl statements
Control statementsCutyChhaya
 
M C6java5
M C6java5M C6java5
M C6java5mbruggen
 
07 flow control
07   flow control07   flow control
07 flow controldhrubo kayal
 
Chapter 4 flow control structures and arrays
Chapter 4 flow control structures and arraysChapter 4 flow control structures and arrays
Chapter 4 flow control structures and arrayssshhzap
 
21. Assertion.ppt
21. Assertion.ppt21. Assertion.ppt
21. Assertion.pptssuserd7ef0c
 
Lecture 3 Conditionals, expressions and Variables
Lecture 3   Conditionals, expressions and VariablesLecture 3   Conditionals, expressions and Variables
Lecture 3 Conditionals, expressions and VariablesSyed Afaq Shah MACS CP
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, LoopingMURALIDHAR R
 
Absolute Java 5e Savitch Test Bank
Absolute Java 5e Savitch Test BankAbsolute Java 5e Savitch Test Bank
Absolute Java 5e Savitch Test BankLauriewest24
 

Similar to Chapter 4.1 (20)

Selection Control Structures
Selection Control StructuresSelection Control Structures
Selection Control Structures
 
Chapter 4.2
Chapter 4.2Chapter 4.2
Chapter 4.2
 
Java input Scanner
Java input Scanner Java input Scanner
Java input Scanner
 
03a control structures
03a   control structures03a   control structures
03a control structures
 
Chapter 4.3
Chapter 4.3Chapter 4.3
Chapter 4.3
 
slides03.ppt
slides03.pptslides03.ppt
slides03.ppt
 
Ap Power Point Chpt3
Ap Power Point Chpt3Ap Power Point Chpt3
Ap Power Point Chpt3
 
Ap Power Point Chpt3 B
Ap Power Point Chpt3 BAp Power Point Chpt3 B
Ap Power Point Chpt3 B
 
Control statements
Control statementsControl statements
Control statements
 
M C6java5
M C6java5M C6java5
M C6java5
 
07 flow control
07   flow control07   flow control
07 flow control
 
Chapter 4 flow control structures and arrays
Chapter 4 flow control structures and arraysChapter 4 flow control structures and arrays
Chapter 4 flow control structures and arrays
 
Ch05-converted.pptx
Ch05-converted.pptxCh05-converted.pptx
Ch05-converted.pptx
 
21. Assertion.ppt
21. Assertion.ppt21. Assertion.ppt
21. Assertion.ppt
 
Flow of control
Flow of controlFlow of control
Flow of control
 
Ch05.pdf
Ch05.pdfCh05.pdf
Ch05.pdf
 
Lecture 3 Conditionals, expressions and Variables
Lecture 3   Conditionals, expressions and VariablesLecture 3   Conditionals, expressions and Variables
Lecture 3 Conditionals, expressions and Variables
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, Looping
 
control structure
control structurecontrol structure
control structure
 
Absolute Java 5e Savitch Test Bank
Absolute Java 5e Savitch Test BankAbsolute Java 5e Savitch Test Bank
Absolute Java 5e Savitch Test Bank
 

More from sotlsoc

Chapter 1.0 new
Chapter 1.0 newChapter 1.0 new
Chapter 1.0 newsotlsoc
 
Chapter 11.1
Chapter 11.1Chapter 11.1
Chapter 11.1sotlsoc
 
Chapter 10.3
Chapter 10.3Chapter 10.3
Chapter 10.3sotlsoc
 
Chapter 11.4
Chapter 11.4Chapter 11.4
Chapter 11.4sotlsoc
 
Chapter 11.3
Chapter 11.3Chapter 11.3
Chapter 11.3sotlsoc
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5sotlsoc
 
Chapter 11.2
Chapter 11.2Chapter 11.2
Chapter 11.2sotlsoc
 
Chapter 10.2
Chapter 10.2Chapter 10.2
Chapter 10.2sotlsoc
 
Chapter 10.1
Chapter 10.1Chapter 10.1
Chapter 10.1sotlsoc
 
Chapter 8.0
Chapter 8.0Chapter 8.0
Chapter 8.0sotlsoc
 
Chapter 9.3
Chapter 9.3Chapter 9.3
Chapter 9.3sotlsoc
 
Chapter 9.4
Chapter 9.4Chapter 9.4
Chapter 9.4sotlsoc
 
Chapter 9.1
Chapter 9.1Chapter 9.1
Chapter 9.1sotlsoc
 
Chapter 8.1
Chapter 8.1Chapter 8.1
Chapter 8.1sotlsoc
 
Chapter 9.0
Chapter 9.0Chapter 9.0
Chapter 9.0sotlsoc
 
Chapter 9.2
Chapter 9.2Chapter 9.2
Chapter 9.2sotlsoc
 
Chapter 8.2
Chapter 8.2Chapter 8.2
Chapter 8.2sotlsoc
 
Chapter 7.4
Chapter 7.4Chapter 7.4
Chapter 7.4sotlsoc
 
Chapter 7.2
Chapter 7.2Chapter 7.2
Chapter 7.2sotlsoc
 
Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6sotlsoc
 

More from sotlsoc (20)

Chapter 1.0 new
Chapter 1.0 newChapter 1.0 new
Chapter 1.0 new
 
Chapter 11.1
Chapter 11.1Chapter 11.1
Chapter 11.1
 
Chapter 10.3
Chapter 10.3Chapter 10.3
Chapter 10.3
 
Chapter 11.4
Chapter 11.4Chapter 11.4
Chapter 11.4
 
Chapter 11.3
Chapter 11.3Chapter 11.3
Chapter 11.3
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
 
Chapter 11.2
Chapter 11.2Chapter 11.2
Chapter 11.2
 
Chapter 10.2
Chapter 10.2Chapter 10.2
Chapter 10.2
 
Chapter 10.1
Chapter 10.1Chapter 10.1
Chapter 10.1
 
Chapter 8.0
Chapter 8.0Chapter 8.0
Chapter 8.0
 
Chapter 9.3
Chapter 9.3Chapter 9.3
Chapter 9.3
 
Chapter 9.4
Chapter 9.4Chapter 9.4
Chapter 9.4
 
Chapter 9.1
Chapter 9.1Chapter 9.1
Chapter 9.1
 
Chapter 8.1
Chapter 8.1Chapter 8.1
Chapter 8.1
 
Chapter 9.0
Chapter 9.0Chapter 9.0
Chapter 9.0
 
Chapter 9.2
Chapter 9.2Chapter 9.2
Chapter 9.2
 
Chapter 8.2
Chapter 8.2Chapter 8.2
Chapter 8.2
 
Chapter 7.4
Chapter 7.4Chapter 7.4
Chapter 7.4
 
Chapter 7.2
Chapter 7.2Chapter 7.2
Chapter 7.2
 
Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6
 

Recently uploaded

Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Recently uploaded (20)

Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

Chapter 4.1

  • 2. 3 Types Flow of Control ï‚ž Sequential (we had learn in previous topic) ï‚— The statements in a program are executed in sequential order ï‚ž Selection ï‚— allow the program to select one of multiple paths of execution. ï‚— The path is selected based on some conditional criteria (boolean expression) ï‚ž Repetition (we will learn in next topic)
  • 3. Flow of Control: Sequential Structures statement1 statement2 statement3
  • 4. Flow of Control: Selection Structures ï‚ž If the boolean expression evaluates to true, the statement will be executed. Otherwise, it will be skipped.
  • 5. Flow of Control: Selection Structures ï‚ž There are 3 types of Java selection structures: ï‚— if statement ï‚— if-else statement ï‚— switch statement
  • 6. The if Statement ï‚ž The if statement has the following syntax: if ( condition ) statement; if is a Java reserved word The condition must be a boolean expression. It must evaluate to either true or false. If the condition is true, the statement is executed. If it is false, the statement is skipped.
  • 7. Logic of an if statement condition evaluated statement true false
  • 8. if Statement if (amount <= balance) balance = balance - amount;
  • 9. Boolean Expressions ï‚ž A condition often uses one of Java's equality operators or relational operators, which all return boolean results: == equal to != not equal to < less than > greater than <= less than or equal to >= greater than or equal to
  • 10. The if Statement if (total > MAX) charge = total * MAX_RATE; System.out.println ("The charge is " + charge); ï‚ž First the condition is evaluated -- the value of total is either greater than the value of MAX ï‚ž If the condition is true, the assignment statement is executed -- if it isn’t, it is skipped. ï‚ž Either way, the call to println is executed next
  • 11. Java code example class Count { public static void main (String args[]) { double y=15.0; double x=25.0; if (y!=x) System.out.println("Result : y not equal x"); } }
  • 12. Output Result : y not equal x
  • 13. Block Statements ï‚ž Several statements can be grouped together into a block statement delimited by braces if (total > MAX) { System.out.println ("Error!!"); errorCount++; }
  • 14. Block Statements if (amount <= balance) { balance = balance - amount; System.out.println(“Acct new balance = “ + balance); } COMPARE WITH if (amount <= balance) balance = balance - amount; System.out.println(“Acct new balance = “ + balance);