SlideShare uma empresa Scribd logo
1 de 10
Control Statements
Prepared by:
Jean Michael Castor
Introduction
• Control statements are used in programming
languages to cause the flow of control to
advance and branch based on changes to the
state of a program.
Introduction
• In Java, control statements can be divided
under the following three categories:
• Selection statements
• Iteration statements
• Jump statements
SELECTION STATEMENTS
• Selection statements are used in a program to
choose different paths of execution based
upon the outcome of an expression or the
state of a variable.
Using if and if...else
• Syntax: if ( Expression ) Statement
• Semantics: The expression must be of type
boolean. If it evaluates to true, the given
statement is executed, otherwise not.
Using if and if...else
• Note that there is only one statement. To
execute more than one statement
conditionally, a block statement is to be used.
Using if and if...else
• In addition, our coding standard expects following
layout:
if ( Expression ) {
Statement1
}
elseif ( Expression ){
Statement 2
}
else{
Statement 3(default value)
}
Example Program
• Write a program that display grade as PASSED
if value is greater than or equal to 75,
otherwise, FAILED.
Solution
public class Grades{
public static void main (String [] args){
int grade;
grade = 10;
if(grade >=75) {
System.out.println(“PASSED”);
}
else if(grade < 75){
System.out.println(“FAILED”);
}
else{
System.out.println(“ ”);
}
}
}

Mais conteúdo relacionado

Mais procurados

Decision statements in vb.net
Decision statements in vb.netDecision statements in vb.net
Decision statements in vb.netilakkiya
 
Vb decision making statements
Vb decision making statementsVb decision making statements
Vb decision making statementspragya ratan
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selectionOnline
 
java programming- control statements
 java programming- control statements java programming- control statements
java programming- control statementsjyoti_lakhani
 
10. switch case
10. switch case10. switch case
10. switch caseWay2itech
 
Exception Handling in VB.Net
Exception Handling in VB.NetException Handling in VB.Net
Exception Handling in VB.Netrishisingh190
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C ProgrammingSonya Akter Rupa
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETUjwala Junghare
 
Control statements
Control statementsControl statements
Control statementsCutyChhaya
 
Python Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and AssertionsPython Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and AssertionsRanel Padon
 
Conditional statement in c
Conditional statement in cConditional statement in c
Conditional statement in cMuthuganesh S
 
Template method pattern example
Template method pattern exampleTemplate method pattern example
Template method pattern exampleGuo Albert
 

Mais procurados (20)

Decision statements in vb.net
Decision statements in vb.netDecision statements in vb.net
Decision statements in vb.net
 
Vb decision making statements
Vb decision making statementsVb decision making statements
Vb decision making statements
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selection
 
Control statements
Control statementsControl statements
Control statements
 
Decisions
DecisionsDecisions
Decisions
 
java programming- control statements
 java programming- control statements java programming- control statements
java programming- control statements
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
C# Basics
C# BasicsC# Basics
C# Basics
 
Control Structures: Part 1
Control Structures: Part 1Control Structures: Part 1
Control Structures: Part 1
 
Controlstatment in c
Controlstatment in cControlstatment in c
Controlstatment in c
 
10. switch case
10. switch case10. switch case
10. switch case
 
Quiz5
Quiz5Quiz5
Quiz5
 
Exception Handling in VB.Net
Exception Handling in VB.NetException Handling in VB.Net
Exception Handling in VB.Net
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C Programming
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NET
 
Switch case in C++
Switch case in C++Switch case in C++
Switch case in C++
 
Control statements
Control statementsControl statements
Control statements
 
Python Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and AssertionsPython Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and Assertions
 
Conditional statement in c
Conditional statement in cConditional statement in c
Conditional statement in c
 
Template method pattern example
Template method pattern exampleTemplate method pattern example
Template method pattern example
 

Semelhante a Control statements in Java

Introduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlIntroduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlENGWAU TONNY
 
Ch # 11 2nd year computer science notes1
Ch # 11 2nd year computer science notes1Ch # 11 2nd year computer science notes1
Ch # 11 2nd year computer science notes1muhammadFaheem656405
 
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
 
Chapter05-Control Structures.pptx
Chapter05-Control Structures.pptxChapter05-Control Structures.pptx
Chapter05-Control Structures.pptxAdrianVANTOPINA
 
Chap11 (ICS12).pdf
Chap11 (ICS12).pdfChap11 (ICS12).pdf
Chap11 (ICS12).pdfJounAbbas4
 
Presentation of control statement
Presentation of control statement  Presentation of control statement
Presentation of control statement Bharat Rathore
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJTANUJ ⠀
 
Java basics and java variables
Java basics and java variablesJava basics and java variables
Java basics and java variablesPushpendra Tyagi
 
IGCSE ICT Chapter 3- Storage devices and media.ppt
IGCSE ICT Chapter 3- Storage devices and media.pptIGCSE ICT Chapter 3- Storage devices and media.ppt
IGCSE ICT Chapter 3- Storage devices and media.pptAakilaliShaikh
 

Semelhante a Control statements in Java (20)

Introduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlIntroduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
 
Java 2.pptx
Java 2.pptxJava 2.pptx
Java 2.pptx
 
Decision making
Decision makingDecision making
Decision making
 
Unit II.pptx
Unit II.pptxUnit II.pptx
Unit II.pptx
 
slides03.ppt
slides03.pptslides03.ppt
slides03.ppt
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
Ch # 11 2nd year computer science notes1
Ch # 11 2nd year computer science notes1Ch # 11 2nd year computer science notes1
Ch # 11 2nd year computer science notes1
 
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
 
DECISION MAKING.pptx
DECISION MAKING.pptxDECISION MAKING.pptx
DECISION MAKING.pptx
 
Chapter05-Control Structures.pptx
Chapter05-Control Structures.pptxChapter05-Control Structures.pptx
Chapter05-Control Structures.pptx
 
Matlab decisions
Matlab decisionsMatlab decisions
Matlab decisions
 
conditional_statement.pdf
conditional_statement.pdfconditional_statement.pdf
conditional_statement.pdf
 
Chap3java5th
Chap3java5thChap3java5th
Chap3java5th
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Java Programming Fundamentals
Java Programming Fundamentals Java Programming Fundamentals
Java Programming Fundamentals
 
Chap11 (ICS12).pdf
Chap11 (ICS12).pdfChap11 (ICS12).pdf
Chap11 (ICS12).pdf
 
Presentation of control statement
Presentation of control statement  Presentation of control statement
Presentation of control statement
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
 
Java basics and java variables
Java basics and java variablesJava basics and java variables
Java basics and java variables
 
IGCSE ICT Chapter 3- Storage devices and media.ppt
IGCSE ICT Chapter 3- Storage devices and media.pptIGCSE ICT Chapter 3- Storage devices and media.ppt
IGCSE ICT Chapter 3- Storage devices and media.ppt
 

Mais de Jin Castor

Information security
 Information security Information security
Information securityJin Castor
 
Introduction to E-commerce
Introduction to E-commerceIntroduction to E-commerce
Introduction to E-commerceJin Castor
 
Introduction to Infographics Designing
Introduction to Infographics DesigningIntroduction to Infographics Designing
Introduction to Infographics DesigningJin Castor
 
Creative designing using Adobe Products
Creative designing using Adobe ProductsCreative designing using Adobe Products
Creative designing using Adobe ProductsJin Castor
 
Introduction to Adobe Illustrator
Introduction to Adobe IllustratorIntroduction to Adobe Illustrator
Introduction to Adobe IllustratorJin Castor
 
SEO Advanced and scalable link building
SEO  Advanced and scalable link building SEO  Advanced and scalable link building
SEO Advanced and scalable link building Jin Castor
 
Introduction to Web Designing
Introduction to Web DesigningIntroduction to Web Designing
Introduction to Web DesigningJin Castor
 
Introduction to search engine optimization
Introduction to search engine optimizationIntroduction to search engine optimization
Introduction to search engine optimizationJin Castor
 
Web services protocols
Web services protocolsWeb services protocols
Web services protocolsJin Castor
 
Web application security
Web application securityWeb application security
Web application securityJin Castor
 
Introduction to xampp
Introduction to xamppIntroduction to xampp
Introduction to xamppJin Castor
 
Drupal introduction
Drupal introductionDrupal introduction
Drupal introductionJin Castor
 
Switch statements in Java
Switch statements  in JavaSwitch statements  in Java
Switch statements in JavaJin Castor
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in JavaJin Castor
 

Mais de Jin Castor (17)

Information security
 Information security Information security
Information security
 
Introduction to E-commerce
Introduction to E-commerceIntroduction to E-commerce
Introduction to E-commerce
 
Introduction to Infographics Designing
Introduction to Infographics DesigningIntroduction to Infographics Designing
Introduction to Infographics Designing
 
Creative designing using Adobe Products
Creative designing using Adobe ProductsCreative designing using Adobe Products
Creative designing using Adobe Products
 
Introduction to Adobe Illustrator
Introduction to Adobe IllustratorIntroduction to Adobe Illustrator
Introduction to Adobe Illustrator
 
SEO Advanced and scalable link building
SEO  Advanced and scalable link building SEO  Advanced and scalable link building
SEO Advanced and scalable link building
 
Introduction to Web Designing
Introduction to Web DesigningIntroduction to Web Designing
Introduction to Web Designing
 
Introduction to search engine optimization
Introduction to search engine optimizationIntroduction to search engine optimization
Introduction to search engine optimization
 
Web services protocols
Web services protocolsWeb services protocols
Web services protocols
 
Web application security
Web application securityWeb application security
Web application security
 
Introduction to xampp
Introduction to xamppIntroduction to xampp
Introduction to xampp
 
Drupal introduction
Drupal introductionDrupal introduction
Drupal introduction
 
Web security
Web securityWeb security
Web security
 
Switch statements in Java
Switch statements  in JavaSwitch statements  in Java
Switch statements in Java
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
 
Java input
Java inputJava input
Java input
 
Java arrays
Java arraysJava arrays
Java arrays
 

Último

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 

Último (20)

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 

Control statements in Java

  • 2. Introduction • Control statements are used in programming languages to cause the flow of control to advance and branch based on changes to the state of a program.
  • 3. Introduction • In Java, control statements can be divided under the following three categories: • Selection statements • Iteration statements • Jump statements
  • 5. • Selection statements are used in a program to choose different paths of execution based upon the outcome of an expression or the state of a variable.
  • 6. Using if and if...else • Syntax: if ( Expression ) Statement • Semantics: The expression must be of type boolean. If it evaluates to true, the given statement is executed, otherwise not.
  • 7. Using if and if...else • Note that there is only one statement. To execute more than one statement conditionally, a block statement is to be used.
  • 8. Using if and if...else • In addition, our coding standard expects following layout: if ( Expression ) { Statement1 } elseif ( Expression ){ Statement 2 } else{ Statement 3(default value) }
  • 9. Example Program • Write a program that display grade as PASSED if value is greater than or equal to 75, otherwise, FAILED.
  • 10. Solution public class Grades{ public static void main (String [] args){ int grade; grade = 10; if(grade >=75) { System.out.println(“PASSED”); } else if(grade < 75){ System.out.println(“FAILED”); } else{ System.out.println(“ ”); } } }