SlideShare a Scribd company logo
L04 - Control Structuresjhgjhgjhgjhgfjgfjhgfjgf.pptx
L04 - Control Structuresjhgjhgjhgjhgfjgfjhgfjgf.pptx
L04 - Control Structuresjhgjhgjhgjhgfjgfjhgfjgf.pptx
L04 - Control Structuresjhgjhgjhgjhgfjgfjhgfjgf.pptx
if (expression) {
statement;
}
rest_of_program;
• expressionbooleantruefalse
expression truestatement rest_of_program
expression falsestatement rest_of_program
statement
rest_of_program
expression
true
if (expression) {
statement1;
}
rest_of_program
if (expression) {
statement1;
}
else{
statement2;
}
next_statement;
expressionboolean
expression truestatement1next_statement
expression falsestatement2next_statement
if (expression){
statement1;
} else {
statement2;
}
rest_of_program
“”
true
statement1
rest_of_program
statement2
if (grade == 'A')
System.out.println("You got an A.");
else if (grade == 'B')
System.out.println("You got a B.");
else if (grade == 'C')
System.out.println("You got a C.");
else
System.out.println("You got an F.");
switch
switch (expression) {
case value1:
statement1;
case value2:
statement2;
default:
default_statement;
}
char, byte, short or int, long, float, or do
uble.
switch (expression){
case value1:
// Do value1 thing
case value2:
// Do value2 thing
...
default:
// Do default action
}
// Continue the program
expression
value1
value1
value2
default action
expression
value2
break
switch (expression) {
case value1:
statement1;
break;
case value2:
statement2;
break;
default:
default_statement;
break;
}
switch (expression){
case value1:
// Do value1 thing
break;
case value2:
// Do value2 thing
break;
...
default:
// Do default action
break;
}
// Continue the program
If-Else
if (grade == 'A')
System.out.println("You got an A.");
else if (grade == 'B')
System.out.println("You got a B.");
else if (grade == 'C')
System.out.println("You got a C.");
else
System.out.println("You got an F.");
“”
switch (grade) {
case 'A':
System.out.println("You got an A.");
break;
case 'B':
System.out.println("You got a B.");
break;
case 'C':
System.out.println("You got a C.");
break;
default:
System.out.println("You got an F.");
}
1. while
2. for
3. do-while
while
while (expression){
statement
}
truefalse
false
int sum = 0;
int i = 1;
while (i <= 10){
sum += i;
i++;
}
sum
do..while
do {
statement
} while (expression);
truefalse
false
int sum = 0;
int i = 1;
do {
sum += i;
i++;
} while (i <= 10);
sum
for
for
init_expression,
loop_condition
increment_expr
for (init_expr; loop_condition; increment_expr) {
statement;
}
int sum = 0;
for (int i = 1; i <= 10; i++) {
sum += i;
}
sum
for(int div = 0; div < 1000; div++){
if(div % 2 == 0) {
System.out.println("even: " + div);
} else {
System.out.println("odd: " + div);
}
}
for(i=0, j=0; i*j < 100; i++, j+=2) {
System.out.println(i * j);
}
int n = 0;
for(; n <= 100;) {
System.out.println(++n);
}
while
for
continue
continue
/**
* prints out "5689"
*/
for(int m = 5; m < 10; m++) {
if(m == 7) {
continue;
}
System.out.print(m);
}
int sum = 0;
for(int i = 1; i <= 10; i++){
if(i % 3 == 0) {
continue;
}
sum += i;
}
sum
break
// prints out numbers unless
// num is ever exactly 400
while (num > 6) {
if(num == 400) {
break;
}
System.out.println(num);
num -= 8;
}
for(int i = 10; i > 0; i--) {
if (i > 7)
continue;
while (i > 3) {
if(i == 5)
break;
System.out.println(--i);
}
System.out.println(i);
}
switchexpression
for
for
for

More Related Content

DOCX
Review questions and answers
DOC
03review
PPTX
JPC#8 Introduction to Java Programming
PPTX
Pj01 5-exceution control flow
PDF
Java_Programming_by_Example_6th_Edition.pdf
PPT
Comp102 lec 5.1
PPTX
Control structures
PDF
Learn Java Part 5
Review questions and answers
03review
JPC#8 Introduction to Java Programming
Pj01 5-exceution control flow
Java_Programming_by_Example_6th_Edition.pdf
Comp102 lec 5.1
Control structures
Learn Java Part 5

Similar to L04 - Control Structuresjhgjhgjhgjhgfjgfjhgfjgf.pptx (20)

PPTX
130706266060138191
PPT
Chapter 1 Nested Control Structures
PDF
Sharable_Java_Python.pdf
PPT
conditional statements
PPT
Control statements
PPT
Chapter 1 nested control structures
PPT
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
PPTX
control statements
PPTX
Control structures in java
PDF
Chapter 00 revision
DOCX
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
PPTX
Control statements in java
PPTX
ICSE Class X Conditional Statements in java
PPTX
Std 12 Computer Chapter 7 Java Basics (Part 2)
PPT
Control statements
PDF
java programming language part-2 decision making .pdf
PPT
Chapter 2&3 (java fundamentals and Control Structures).ppt
PDF
OIT 116 LOOPS AND CONDITION STATEMENTS.pdf
PPT
Java Programmin: Selections
130706266060138191
Chapter 1 Nested Control Structures
Sharable_Java_Python.pdf
conditional statements
Control statements
Chapter 1 nested control structures
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
control statements
Control structures in java
Chapter 00 revision
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
Control statements in java
ICSE Class X Conditional Statements in java
Std 12 Computer Chapter 7 Java Basics (Part 2)
Control statements
java programming language part-2 decision making .pdf
Chapter 2&3 (java fundamentals and Control Structures).ppt
OIT 116 LOOPS AND CONDITION STATEMENTS.pdf
Java Programmin: Selections
Ad

More from EliasPetros (12)

PPTX
ghgfjfhgdjfdhgdhgfdgfdhgdhgfdhgzeka.pptx
PPT
lkjhlkjhjhkjhlkjhkjhkjhkjhkjhkjhjhkjh.ppt
PPTX
ehhhhhhhhhhhhhhhhhhhhhhhhhjjjjjllaye.pptx
PPTX
Database Akjljljlkjlkjkljlkjldiministration.pptx
PPTX
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
PPTX
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
PPTX
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
PPTX
Python.pptx
PPTX
Chapter 08.pptx
PPT
chaptet 4 DC and CN.ppt
PPTX
5_6278455688045789623.pptx
PPT
chapter 1 DC and CN-1.ppt
ghgfjfhgdjfdhgdhgfdgfdhgdhgfdhgzeka.pptx
lkjhlkjhjhkjhlkjhkjhkjhkjhkjhkjhjhkjh.ppt
ehhhhhhhhhhhhhhhhhhhhhhhhhjjjjjllaye.pptx
Database Akjljljlkjlkjkljlkjldiministration.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
Python.pptx
Chapter 08.pptx
chaptet 4 DC and CN.ppt
5_6278455688045789623.pptx
chapter 1 DC and CN-1.ppt
Ad

Recently uploaded (20)

PPTX
The Marketing Journey - Tracey Phillips - Marketing Matters 7-2025.pptx
PDF
Solara Labs: Empowering Health through Innovative Nutraceutical Solutions
PDF
Business model innovation report 2022.pdf
PDF
How to Get Business Funding for Small Business Fast
DOCX
unit 1 COST ACCOUNTING AND COST SHEET
DOCX
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
PPTX
New Microsoft PowerPoint Presentation - Copy.pptx
PPTX
Amazon (Business Studies) management studies
PDF
pdfcoffee.com-opt-b1plus-sb-answers.pdfvi
PPTX
HR Introduction Slide (1).pptx on hr intro
PPTX
Principles of Marketing, Industrial, Consumers,
PDF
COST SHEET- Tender and Quotation unit 2.pdf
PDF
Training And Development of Employee .pdf
PDF
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
PPTX
ICG2025_ICG 6th steering committee 30-8-24.pptx
PDF
MSPs in 10 Words - Created by US MSP Network
DOCX
Euro SEO Services 1st 3 General Updates.docx
PDF
Reconciliation AND MEMORANDUM RECONCILATION
PPTX
Belch_12e_PPT_Ch18_Accessible_university.pptx
PDF
20250805_A. Stotz All Weather Strategy - Performance review July 2025.pdf
The Marketing Journey - Tracey Phillips - Marketing Matters 7-2025.pptx
Solara Labs: Empowering Health through Innovative Nutraceutical Solutions
Business model innovation report 2022.pdf
How to Get Business Funding for Small Business Fast
unit 1 COST ACCOUNTING AND COST SHEET
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
New Microsoft PowerPoint Presentation - Copy.pptx
Amazon (Business Studies) management studies
pdfcoffee.com-opt-b1plus-sb-answers.pdfvi
HR Introduction Slide (1).pptx on hr intro
Principles of Marketing, Industrial, Consumers,
COST SHEET- Tender and Quotation unit 2.pdf
Training And Development of Employee .pdf
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
ICG2025_ICG 6th steering committee 30-8-24.pptx
MSPs in 10 Words - Created by US MSP Network
Euro SEO Services 1st 3 General Updates.docx
Reconciliation AND MEMORANDUM RECONCILATION
Belch_12e_PPT_Ch18_Accessible_university.pptx
20250805_A. Stotz All Weather Strategy - Performance review July 2025.pdf

L04 - Control Structuresjhgjhgjhgjhgfjgfjhgfjgf.pptx

Editor's Notes

  • #25: Out put for firt one is i=0 j= 0=0 i=1,j=2=2 i=2,j=4=8 18 32 50 72 98