SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Andere mochten auch

Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in JavaJin Castor
 
Classes revision
Classes revisionClasses revision
Classes revisionASU Online
 
4. Classes and Methods
4. Classes and Methods4. Classes and Methods
4. Classes and MethodsNilesh Dalvi
 
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 sekolahUniversity of Putra
 
GCSE year 9 options evening
GCSE year 9 options eveningGCSE year 9 options evening
GCSE year 9 options eveningbsharland
 
A453 programming task 1
A453 programming task 1A453 programming task 1
A453 programming task 1Tom Dale
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in javaHitesh Kumar
 
Spesifikasi program dengan Java
Spesifikasi program dengan JavaSpesifikasi program dengan Java
Spesifikasi program dengan JavaOkta Riveranda
 
Proposal ringkas HBL
Proposal ringkas HBLProposal ringkas HBL
Proposal ringkas HBLsyedayuuras
 
Chapter 1 introduction to java technology
Chapter 1 introduction to java technologyChapter 1 introduction to java technology
Chapter 1 introduction to java technologysshhzap
 
5.3.1 bahasa pengaturcaraan terkini
5.3.1 bahasa pengaturcaraan terkini5.3.1 bahasa pengaturcaraan terkini
5.3.1 bahasa pengaturcaraan terkinidean36
 
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 Cikgu Comel
 
Basics of reflection in java
Basics of reflection in javaBasics of reflection in java
Basics of reflection in javakim.mens
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javaASU Online
 
Reflection in java
Reflection in javaReflection in java
Reflection in javaupen.rockin
 
Penerapan KBAT - SLOT 4
Penerapan KBAT - SLOT 4Penerapan KBAT - SLOT 4
Penerapan KBAT - SLOT 4MOHD AFIQ
 

Andere mochten auch (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
 

Ähnlich wie For loop java 2

Ähnlich wie 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
 

Mehr von ASU Online

Midterm common mistakes
Midterm common mistakesMidterm common mistakes
Midterm common mistakesASU Online
 
Lists, queues and stacks 1
Lists, queues and stacks 1Lists, queues and stacks 1
Lists, queues and stacks 1ASU Online
 
Lists, queues and stacks
Lists, queues and stacksLists, queues and stacks
Lists, queues and stacksASU Online
 
Reading and writting v2
Reading and writting v2Reading and writting v2
Reading and writting v2ASU Online
 
Common errors v2
Common errors v2Common errors v2
Common errors v2ASU Online
 
Common missunderestandings
Common missunderestandingsCommon missunderestandings
Common missunderestandingsASU Online
 
Lecture 14 tourism in europe
Lecture 14   tourism in europeLecture 14   tourism in europe
Lecture 14 tourism in europeASU 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 pacificASU 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 zealandASU Online
 
Lecture 11 tourism in east asia
Lecture 11   tourism in east asiaLecture 11   tourism in east asia
Lecture 11 tourism in east asiaASU Online
 
Lecture 9 tourism in south asia
Lecture 9   tourism in south asiaLecture 9   tourism in south asia
Lecture 9 tourism in south asiaASU 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-1ASU Online
 
Lecture 8 tourism in central asia
Lecture 8   tourism in central asiaLecture 8   tourism in central asia
Lecture 8 tourism in central asiaASU 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 africaASU 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 africaASU Online
 
Lecture 5 tourism in latin america
Lecture 5   tourism in latin americaLecture 5   tourism in latin america
Lecture 5 tourism in latin americaASU Online
 
Lecture 4 tourism in the caribbean
Lecture 4   tourism in the caribbeanLecture 4   tourism in the caribbean
Lecture 4 tourism in the caribbeanASU 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 tourismASU 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 distASU Online
 
Lecture 10 tourism in southeast asia
Lecture 10   tourism in southeast asiaLecture 10   tourism in southeast asia
Lecture 10 tourism in southeast asiaASU Online
 

Mehr von 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
 

Kürzlich hochgeladen

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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)Zilliz
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
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 TerraformAndrey Devyatkin
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
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 2024Victor Rentea
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
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 FMESafe Software
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 

Kürzlich hochgeladen (20)

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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)
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 

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