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 bas...
Introduction
• In Java, control statements can be divided
under the following three categories:
• Selection statements
• I...
SELECTION STATEMENTS
• Selection statements are used in a program to
choose different paths of execution based
upon the outcome of an expressio...
Using if and if...else
• Syntax: if ( Expression ) Statement
• Semantics: The expression must be of type
boolean. If it ev...
Using if and if...else
• Note that there is only one statement. To
execute more than one statement
conditionally, a block ...
Using if and if...else
• In addition, our coding standard expects following
layout:
if ( Expression ) {
Statement1
}
elsei...
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...
Upcoming SlideShare
Loading in...5
×

Control statements in Java

461

Published on

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
461
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
23
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Control statements in Java

  1. 1. Control Statements Prepared by: Jean Michael Castor
  2. 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. 3. Introduction • In Java, control statements can be divided under the following three categories: • Selection statements • Iteration statements • Jump statements
  4. 4. SELECTION STATEMENTS
  5. 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. 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. 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. 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. 9. Example Program • Write a program that display grade as PASSED if value is greater than or equal to 75, otherwise, FAILED.
  10. 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(“ ”); } } }
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×