SlideShare uma empresa Scribd logo
1 de 13
For Loop
CST200 – Week 2: For loop example

Instructor: Andreea Molnar
Print the numbers from 0 to 2
for (int i=0; i<3; i++) {
System.out.println(i);

What happens when the program runs

}
i
0

Step 1:
int i=0; // i is initialised with 0

//this is done only once
Print the numbers from 0 to 2
for (int i=0; i<3; i++) {
System.out.println(i);
Step 2:

}
i
0

What happens when the program runs

i<3; // this condition is verified
//i in this case is 0
//the codition becomes 0<3 which is
true, therefore it exectures the loop
statements (the statements between the
brakets {}, or if no braket the first
statement after the for
Print the numbers from 0 to 2
for (int i=0; i<3; i++) {
System.out.println(i);
}

What happens when the program runs

Step 3:
i

//notice that i++ is ignored at this step

0

System.out.println(i);
// the program prints i
//i is 0, therefore 0 will be printed
Print the numbers from 0 to 2
for (int i=0; i<3; i++) {
System.out.println(i);
}

What happens when the program runs

Step 4:
i

01

//the program reaches the } and it returns
to the for; it starts with the i++ part of
the for loop
i++; // i is incremented by 1
// i was 0, and it becomes as a result 1
Print the numbers from 0 to 2
for (int i=0; i<3; i++) {
System.out.println(i);
Step 6:

}
i
1

What happens when the program runs

i<3; // this condition is verified
//i in this case is 1
//the codition becomes 0<3 which is
true, therefore it exectures the loop
statements (the statements between the
brakets {}, or if no braket the first
statement after the for
Print the numbers from 0 to 2
for (int i=0; i<3; i++) {
System.out.println(i);

What happens when the program runs

}
i
1

Step 7:
System.out.println(i);

// the program prints i
//i is 1, therefore 1 will be printed
Print the numbers from 0 to 2
for (int i=0; i<3; i++) {
System.out.println(i);
}

What happens when the program runs

Step 8:
i

12

//the program reaches the } and it returns
to the for; it starts with the i++ part of
the for loop
i++; // i is incremented by 1
// i was 1, and it becomes as a result 2
Print the numbers from 0 to 2
for (int i=0; i<3; i++) {
System.out.println(i);
Step 9:

}
i
2

What happens when the program runs

i<3; // this condition is verified
//i in this case is 2
//the codition becomes 0<3 which is
true, therefore it exectures the loop
statements (the statements between the
brakets {}, or if no braket the first
statement after the for
Print the numbers from 0 to 2
for (int i=0; i<3; i++) {
System.out.println(i);

What happens when the program runs

}
i
2

Step 10:
System.out.println(i);

// the program prints i
//i is 2, therefore 2 will be printed
Print the numbers from 0 to 2
for (int i=0; i<3; i++) {
System.out.println(i);
}

What happens when the program runs

Step 8:
i

23

//the program reaches the } and it returns
to the for; it starts with the i++ part of
the for loop
i++; // i is incremented by 1
// i was 2, and it becomes as a result 3
Print the numbers from 0 to 2
for (int i=0; i<3; i++) {
System.out.println(i);
}

Step 11:
i

3

What happens when the program runs

i<3; // this condition is verified
//i in this case is 3

//the codition becomes 0<3 which is
true, therefore it exectures the loop
statements (the statements between the
brakets {}, or if no braket the first
statement after the for
Summary

Mais conteúdo relacionado

Destaque

Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
Jin Castor
 
Classes revision
Classes revisionClasses revision
Classes revision
ASU Online
 
A453 programming task 1
A453 programming task 1A453 programming task 1
A453 programming task 1
Tom Dale
 
Proposal ringkas HBL
Proposal ringkas HBLProposal ringkas HBL
Proposal ringkas HBL
syedayuuras
 
Chapter 1 introduction to java technology
Chapter 1 introduction to java technologyChapter 1 introduction to java technology
Chapter 1 introduction to java technology
sshhzap
 
5.3.1 bahasa pengaturcaraan terkini
5.3.1 bahasa pengaturcaraan terkini5.3.1 bahasa pengaturcaraan terkini
5.3.1 bahasa pengaturcaraan terkini
dean36
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
ASU Online
 
Reflection in java
Reflection in javaReflection in java
Reflection in java
upen.rockin
 

Destaque (20)

Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
 
Classes revision
Classes revisionClasses revision
Classes revision
 
4. Classes and Methods
4. Classes and Methods4. Classes and Methods
4. Classes and Methods
 
Gaya hidup flow chart, carta gantt dan milestone kpt sekolah
Gaya hidup flow chart, carta gantt dan milestone kpt sekolahGaya hidup flow chart, carta gantt dan milestone kpt sekolah
Gaya hidup flow chart, carta gantt dan milestone kpt sekolah
 
GCSE year 9 options evening
GCSE year 9 options eveningGCSE year 9 options evening
GCSE year 9 options evening
 
T3ST221
T3ST221T3ST221
T3ST221
 
A453 programming task 1
A453 programming task 1A453 programming task 1
A453 programming task 1
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
 
Sktlyda13
Sktlyda13Sktlyda13
Sktlyda13
 
Spesifikasi program dengan Java
Spesifikasi program dengan JavaSpesifikasi program dengan Java
Spesifikasi program dengan Java
 
Proposal ringkas HBL
Proposal ringkas HBLProposal ringkas HBL
Proposal ringkas HBL
 
Chapter 1 introduction to java technology
Chapter 1 introduction to java technologyChapter 1 introduction to java technology
Chapter 1 introduction to java technology
 
Lesson planjessminggu1 2017
Lesson planjessminggu1 2017Lesson planjessminggu1 2017
Lesson planjessminggu1 2017
 
5.3.1 bahasa pengaturcaraan terkini
5.3.1 bahasa pengaturcaraan terkini5.3.1 bahasa pengaturcaraan terkini
5.3.1 bahasa pengaturcaraan terkini
 
RPH BAB 3 RANGKAIAN KOMPUTER DAN KOMUNIKASI
RPH BAB 3 RANGKAIAN KOMPUTER DAN KOMUNIKASI RPH BAB 3 RANGKAIAN KOMPUTER DAN KOMUNIKASI
RPH BAB 3 RANGKAIAN KOMPUTER DAN KOMUNIKASI
 
Basics of reflection in java
Basics of reflection in javaBasics of reflection in java
Basics of reflection in java
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
RPH Sains Komputer PdP 2 SP 1.1.1.3
RPH Sains Komputer PdP 2 SP 1.1.1.3RPH Sains Komputer PdP 2 SP 1.1.1.3
RPH Sains Komputer PdP 2 SP 1.1.1.3
 
Reflection in java
Reflection in javaReflection in java
Reflection in java
 
Penerapan KBAT - SLOT 4
Penerapan KBAT - SLOT 4Penerapan KBAT - SLOT 4
Penerapan KBAT - SLOT 4
 

Semelhante a For loop java 2

Java căn bản - Chapter6
Java căn bản - Chapter6Java căn bản - Chapter6
Java căn bản - Chapter6
Vince Vo
 

Semelhante a For loop java 2 (20)

Ch5(loops)
Ch5(loops)Ch5(loops)
Ch5(loops)
 
Psuedocode1, algorithm1, Flowchart1.pptx
Psuedocode1, algorithm1, Flowchart1.pptxPsuedocode1, algorithm1, Flowchart1.pptx
Psuedocode1, algorithm1, Flowchart1.pptx
 
ParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdf
 
Week2 ch4 part1edited 2020
Week2 ch4 part1edited 2020Week2 ch4 part1edited 2020
Week2 ch4 part1edited 2020
 
Week2 ch4 part1edited 2020
Week2 ch4 part1edited 2020Week2 ch4 part1edited 2020
Week2 ch4 part1edited 2020
 
Python for Beginners(v2)
Python for Beginners(v2)Python for Beginners(v2)
Python for Beginners(v2)
 
Chapter 3 branching v4
Chapter 3 branching v4Chapter 3 branching v4
Chapter 3 branching v4
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Chap 4 c++
Chap 4 c++Chap 4 c++
Chap 4 c++
 
C++ Course - Lesson 1
C++ Course - Lesson 1C++ Course - Lesson 1
C++ Course - Lesson 1
 
OXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART IOXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART I
 
Example : parallelize a simple problem
Example : parallelize a simple problemExample : parallelize a simple problem
Example : parallelize a simple problem
 
Python programming workshop session 2
Python programming workshop session 2Python programming workshop session 2
Python programming workshop session 2
 
Java căn bản - Chapter6
Java căn bản - Chapter6Java căn bản - Chapter6
Java căn bản - Chapter6
 
Chap 4 c++
Chap 4 c++Chap 4 c++
Chap 4 c++
 
Fundamentals of Programming Chapter 3
Fundamentals of Programming Chapter 3Fundamentals of Programming Chapter 3
Fundamentals of Programming Chapter 3
 
1660213363910.pdf
1660213363910.pdf1660213363910.pdf
1660213363910.pdf
 
CST2403 NOTES
CST2403 NOTESCST2403 NOTES
CST2403 NOTES
 

Mais de ASU Online

Midterm common mistakes
Midterm common mistakesMidterm common mistakes
Midterm common mistakes
ASU Online
 
Lists, queues and stacks 1
Lists, queues and stacks 1Lists, queues and stacks 1
Lists, queues and stacks 1
ASU Online
 
Lists, queues and stacks
Lists, queues and stacksLists, queues and stacks
Lists, queues and stacks
ASU Online
 
Reading and writting v2
Reading and writting v2Reading and writting v2
Reading and writting v2
ASU Online
 
Common errors v2
Common errors v2Common errors v2
Common errors v2
ASU Online
 
Common missunderestandings
Common missunderestandingsCommon missunderestandings
Common missunderestandings
ASU Online
 
Lecture 14 tourism in europe
Lecture 14   tourism in europeLecture 14   tourism in europe
Lecture 14 tourism in europe
ASU Online
 
Lecture 13 tourism in the south pacific
Lecture 13   tourism in the south pacificLecture 13   tourism in the south pacific
Lecture 13 tourism in the south pacific
ASU Online
 
Lecture 12 tourism in australia and new zealand
Lecture 12   tourism in australia and new zealandLecture 12   tourism in australia and new zealand
Lecture 12 tourism in australia and new zealand
ASU Online
 
Lecture 11 tourism in east asia
Lecture 11   tourism in east asiaLecture 11   tourism in east asia
Lecture 11 tourism in east asia
ASU Online
 
Lecture 9 tourism in south asia
Lecture 9   tourism in south asiaLecture 9   tourism in south asia
Lecture 9 tourism in south asia
ASU Online
 
Lecture 9 tourism in south asia-1
Lecture 9   tourism in south asia-1Lecture 9   tourism in south asia-1
Lecture 9 tourism in south asia-1
ASU Online
 
Lecture 8 tourism in central asia
Lecture 8   tourism in central asiaLecture 8   tourism in central asia
Lecture 8 tourism in central asia
ASU Online
 
Lecture 7 tourism in the middle east and north africa
Lecture 7   tourism in the middle east and north africaLecture 7   tourism in the middle east and north africa
Lecture 7 tourism in the middle east and north africa
ASU Online
 
Lecture 6 tourism in sub-saharan africa
Lecture 6   tourism in sub-saharan africaLecture 6   tourism in sub-saharan africa
Lecture 6 tourism in sub-saharan africa
ASU Online
 
Lecture 5 tourism in latin america
Lecture 5   tourism in latin americaLecture 5   tourism in latin america
Lecture 5 tourism in latin america
ASU Online
 
Lecture 4 tourism in the caribbean
Lecture 4   tourism in the caribbeanLecture 4   tourism in the caribbean
Lecture 4 tourism in the caribbean
ASU Online
 
Lecture 3 political context of international tourism
Lecture 3   political context of international tourismLecture 3   political context of international tourism
Lecture 3 political context of international tourism
ASU Online
 
Lecture 2 impacts of tourism global dist
Lecture 2 impacts of tourism   global distLecture 2 impacts of tourism   global dist
Lecture 2 impacts of tourism global dist
ASU Online
 
Lecture 10 tourism in southeast asia
Lecture 10   tourism in southeast asiaLecture 10   tourism in southeast asia
Lecture 10 tourism in southeast asia
ASU Online
 

Mais de ASU Online (20)

Midterm common mistakes
Midterm common mistakesMidterm common mistakes
Midterm common mistakes
 
Lists, queues and stacks 1
Lists, queues and stacks 1Lists, queues and stacks 1
Lists, queues and stacks 1
 
Lists, queues and stacks
Lists, queues and stacksLists, queues and stacks
Lists, queues and stacks
 
Reading and writting v2
Reading and writting v2Reading and writting v2
Reading and writting v2
 
Common errors v2
Common errors v2Common errors v2
Common errors v2
 
Common missunderestandings
Common missunderestandingsCommon missunderestandings
Common missunderestandings
 
Lecture 14 tourism in europe
Lecture 14   tourism in europeLecture 14   tourism in europe
Lecture 14 tourism in europe
 
Lecture 13 tourism in the south pacific
Lecture 13   tourism in the south pacificLecture 13   tourism in the south pacific
Lecture 13 tourism in the south pacific
 
Lecture 12 tourism in australia and new zealand
Lecture 12   tourism in australia and new zealandLecture 12   tourism in australia and new zealand
Lecture 12 tourism in australia and new zealand
 
Lecture 11 tourism in east asia
Lecture 11   tourism in east asiaLecture 11   tourism in east asia
Lecture 11 tourism in east asia
 
Lecture 9 tourism in south asia
Lecture 9   tourism in south asiaLecture 9   tourism in south asia
Lecture 9 tourism in south asia
 
Lecture 9 tourism in south asia-1
Lecture 9   tourism in south asia-1Lecture 9   tourism in south asia-1
Lecture 9 tourism in south asia-1
 
Lecture 8 tourism in central asia
Lecture 8   tourism in central asiaLecture 8   tourism in central asia
Lecture 8 tourism in central asia
 
Lecture 7 tourism in the middle east and north africa
Lecture 7   tourism in the middle east and north africaLecture 7   tourism in the middle east and north africa
Lecture 7 tourism in the middle east and north africa
 
Lecture 6 tourism in sub-saharan africa
Lecture 6   tourism in sub-saharan africaLecture 6   tourism in sub-saharan africa
Lecture 6 tourism in sub-saharan africa
 
Lecture 5 tourism in latin america
Lecture 5   tourism in latin americaLecture 5   tourism in latin america
Lecture 5 tourism in latin america
 
Lecture 4 tourism in the caribbean
Lecture 4   tourism in the caribbeanLecture 4   tourism in the caribbean
Lecture 4 tourism in the caribbean
 
Lecture 3 political context of international tourism
Lecture 3   political context of international tourismLecture 3   political context of international tourism
Lecture 3 political context of international tourism
 
Lecture 2 impacts of tourism global dist
Lecture 2 impacts of tourism   global distLecture 2 impacts of tourism   global dist
Lecture 2 impacts of tourism global dist
 
Lecture 10 tourism in southeast asia
Lecture 10   tourism in southeast asiaLecture 10   tourism in southeast asia
Lecture 10 tourism in southeast asia
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 

For loop java 2

  • 1. For Loop CST200 – Week 2: For loop example Instructor: Andreea Molnar
  • 2. Print the numbers from 0 to 2 for (int i=0; i<3; i++) { System.out.println(i); What happens when the program runs } i 0 Step 1: int i=0; // i is initialised with 0 //this is done only once
  • 3. Print the numbers from 0 to 2 for (int i=0; i<3; i++) { System.out.println(i); Step 2: } i 0 What happens when the program runs i<3; // this condition is verified //i in this case is 0 //the codition becomes 0<3 which is true, therefore it exectures the loop statements (the statements between the brakets {}, or if no braket the first statement after the for
  • 4. Print the numbers from 0 to 2 for (int i=0; i<3; i++) { System.out.println(i); } What happens when the program runs Step 3: i //notice that i++ is ignored at this step 0 System.out.println(i); // the program prints i //i is 0, therefore 0 will be printed
  • 5. Print the numbers from 0 to 2 for (int i=0; i<3; i++) { System.out.println(i); } What happens when the program runs Step 4: i 01 //the program reaches the } and it returns to the for; it starts with the i++ part of the for loop i++; // i is incremented by 1 // i was 0, and it becomes as a result 1
  • 6. Print the numbers from 0 to 2 for (int i=0; i<3; i++) { System.out.println(i); Step 6: } i 1 What happens when the program runs i<3; // this condition is verified //i in this case is 1 //the codition becomes 0<3 which is true, therefore it exectures the loop statements (the statements between the brakets {}, or if no braket the first statement after the for
  • 7. Print the numbers from 0 to 2 for (int i=0; i<3; i++) { System.out.println(i); What happens when the program runs } i 1 Step 7: System.out.println(i); // the program prints i //i is 1, therefore 1 will be printed
  • 8. Print the numbers from 0 to 2 for (int i=0; i<3; i++) { System.out.println(i); } What happens when the program runs Step 8: i 12 //the program reaches the } and it returns to the for; it starts with the i++ part of the for loop i++; // i is incremented by 1 // i was 1, and it becomes as a result 2
  • 9. Print the numbers from 0 to 2 for (int i=0; i<3; i++) { System.out.println(i); Step 9: } i 2 What happens when the program runs i<3; // this condition is verified //i in this case is 2 //the codition becomes 0<3 which is true, therefore it exectures the loop statements (the statements between the brakets {}, or if no braket the first statement after the for
  • 10. Print the numbers from 0 to 2 for (int i=0; i<3; i++) { System.out.println(i); What happens when the program runs } i 2 Step 10: System.out.println(i); // the program prints i //i is 2, therefore 2 will be printed
  • 11. Print the numbers from 0 to 2 for (int i=0; i<3; i++) { System.out.println(i); } What happens when the program runs Step 8: i 23 //the program reaches the } and it returns to the for; it starts with the i++ part of the for loop i++; // i is incremented by 1 // i was 2, and it becomes as a result 3
  • 12. Print the numbers from 0 to 2 for (int i=0; i<3; i++) { System.out.println(i); } Step 11: i 3 What happens when the program runs i<3; // this condition is verified //i in this case is 3 //the codition becomes 0<3 which is true, therefore it exectures the loop statements (the statements between the brakets {}, or if no braket the first statement after the for