SlideShare una empresa de 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(“ ”);
}
}
}

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Similar 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
 

Similar 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
 

Más 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
 

Más 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

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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
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
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
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
 
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
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 

Último (20)

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!
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
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
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
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
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
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
 
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
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 

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(“ ”); } } }