SlideShare a Scribd company logo
Revision Exercises on “Loops”
while loop for loop do while   Vs    while loops Agenda
while loop
while loop inti = 0; while (i < 101) { // Processing    : i++;  // at the end }
Write a while loop to solve the following problem    Annie has $0 at the start, she saves $300 per month.  What will she save after 24 months? Exercise 1
How many variables we need? saving (start from 0) month (start from 1) savingPerMth = 300 Problem solving: variables?
int saving = 0; int month = 1; intsavingPerMth = 300; while (month <= 24) {   saving = saving + savingPerMth;  // saving += savingPerMth   month++; } Console.WriteLine(“Total saving = ” + saving.ToString() ); Possible solution
Write a while loop to solve the following problem     John has $300 at the start, she saves $100 per month.        For every 6 months after he gets his bonuses, he saves extra $500.      What will he save after 12 months? Exercise 2
int saving = 300; int month = 1; intsavingPerMth = 100; int bonus = 500; while (month <= 12) {   saving +=  savingPerMth;  // saving += savingPerMth   if ( (month%6) == 0) { saving += bonus; }   month++; } Console.WriteLine(“Total saving = ” + saving.ToString() ); Possible solution
for loop for (inti=0;  i < 101;  i++  )   {     // Processing }
Write a while loop to solve the following problem     Annie has $0 at the start, she saves $300 per month.  What will she save after 24 months? Exercise 1 using for loop
int saving = 0; intsavingPerMth = 300; for (int month=1; month<=24; month++) {   saving += savingPerMth;  } Console.WriteLine(“Total saving = ” + saving.ToString() ); Possible solution
Write a while loop to solve the following problem     John has $300 at the start, she saves $100 per month.        For every 6 months after he gets his bonuses, he saves extra $500.      What will he save after 12 months? Exercise 2 using for loop
int saving = 300; intsavingPerMth = 100; int bonus = 500; for (int month=1; month<=12; month++) {        saving += savingPerMth;       if ( (month%6) == 0)  { saving += bonus;  } } Console.WriteLine(“Total saving = ” + saving.ToString() ); Possible solution
a)  write a for loop to output 0 to 10 b)  write a for loop to output 10, 8, 6, 4, 2 and 0 Exercise 3 using for loop
a)     for (int x = 0; x <=10; x++)    { Console.WriteLine( x.ToString()  );    } b)    for (int x = 10; x >=0; x = x -2)    { Console.WriteLine( x.ToString()  );    } Possible solution
do loop do { } while (   );    // End condition // The difference between the "while" and "do while" loops is that the code in a do while loop will get executed at least once, because its while part is at the end.

More Related Content

What's hot

なぜデータモデリングが重要なのか?
なぜデータモデリングが重要なのか?なぜデータモデリングが重要なのか?
なぜデータモデリングが重要なのか?
Yoshitaka Kawashima
 
Cost of delay and prioritization techniques
Cost of delay and prioritization techniquesCost of delay and prioritization techniques
Cost of delay and prioritization techniques
Murali Mohan Narayanabhatla
 
Cost of delay (WSJF) - Roni Tamari
Cost of delay (WSJF) - Roni TamariCost of delay (WSJF) - Roni Tamari
Cost of delay (WSJF) - Roni Tamari
AgileSparks
 
Java Code Review Checklist
Java Code Review ChecklistJava Code Review Checklist
Java Code Review Checklist
Mahesh Chopker
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
Nikolay Vasilev
 
The agile way (Agile foundations)
The agile way (Agile foundations)The agile way (Agile foundations)
The agile way (Agile foundations)
Laia Poyatos
 
Champfrogs
ChampfrogsChampfrogs
Champfrogs
Jurgen Appelo
 
Agile Mindset Shifting: Agile For All
Agile Mindset Shifting: Agile For AllAgile Mindset Shifting: Agile For All
Agile Mindset Shifting: Agile For All
India Scrum Enthusiasts Community
 
The Executives Step-by-Step Guide to Leading a Large-Scale Agile Transformation
The Executives Step-by-Step Guide to Leading a Large-Scale Agile TransformationThe Executives Step-by-Step Guide to Leading a Large-Scale Agile Transformation
The Executives Step-by-Step Guide to Leading a Large-Scale Agile Transformation
LeadingAgile
 
今どきのアーキテクチャ設計戦略 - QCon Tokyo 2016
今どきのアーキテクチャ設計戦略 - QCon Tokyo 2016今どきのアーキテクチャ設計戦略 - QCon Tokyo 2016
今どきのアーキテクチャ設計戦略 - QCon Tokyo 2016
Yusuke Suzuki
 
Modern Agile Management and Leadership
Modern Agile Management and LeadershipModern Agile Management and Leadership
Modern Agile Management and Leadership
Antti Kirjavainen
 
Hook me UP ( React Hooks Introduction)
Hook me UP ( React Hooks Introduction)Hook me UP ( React Hooks Introduction)
Hook me UP ( React Hooks Introduction)
Carlos Mafla
 
Custom-tailored Agility with the Agile Fluency™ Model
Custom-tailored Agility with the Agile Fluency™ ModelCustom-tailored Agility with the Agile Fluency™ Model
Custom-tailored Agility with the Agile Fluency™ Model
Ahmed Avais
 
アジャイル開発を支えるアーキテクチャ設計とは
アジャイル開発を支えるアーキテクチャ設計とはアジャイル開発を支えるアーキテクチャ設計とは
アジャイル開発を支えるアーキテクチャ設計とは
Yusuke Suzuki
 
サイボウズの生産性を高める生産性向上チームと開発文化
サイボウズの生産性を高める生産性向上チームと開発文化サイボウズの生産性を高める生産性向上チームと開発文化
サイボウズの生産性を高める生産性向上チームと開発文化
Futa HIRAKOBA
 
The Developer Experience
The Developer ExperienceThe Developer Experience
The Developer Experience
Atlassian
 
Foundations of the Scaled Agile Framework: Be Agile. Scale Up. Stay Lean. And...
Foundations of the Scaled Agile Framework: Be Agile. Scale Up. Stay Lean. And...Foundations of the Scaled Agile Framework: Be Agile. Scale Up. Stay Lean. And...
Foundations of the Scaled Agile Framework: Be Agile. Scale Up. Stay Lean. And...
IBM Rational software
 
アジャイルメトリクス実践ガイド
アジャイルメトリクス実践ガイドアジャイルメトリクス実践ガイド
アジャイルメトリクス実践ガイド
Hiroyuki Ito
 
Hexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootHexagonal architecture with Spring Boot
Hexagonal architecture with Spring Boot
Mikalai Alimenkou
 
Agile Transformation v1.27
Agile Transformation v1.27Agile Transformation v1.27
Agile Transformation v1.27
LeadingAgile
 

What's hot (20)

なぜデータモデリングが重要なのか?
なぜデータモデリングが重要なのか?なぜデータモデリングが重要なのか?
なぜデータモデリングが重要なのか?
 
Cost of delay and prioritization techniques
Cost of delay and prioritization techniquesCost of delay and prioritization techniques
Cost of delay and prioritization techniques
 
Cost of delay (WSJF) - Roni Tamari
Cost of delay (WSJF) - Roni TamariCost of delay (WSJF) - Roni Tamari
Cost of delay (WSJF) - Roni Tamari
 
Java Code Review Checklist
Java Code Review ChecklistJava Code Review Checklist
Java Code Review Checklist
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
The agile way (Agile foundations)
The agile way (Agile foundations)The agile way (Agile foundations)
The agile way (Agile foundations)
 
Champfrogs
ChampfrogsChampfrogs
Champfrogs
 
Agile Mindset Shifting: Agile For All
Agile Mindset Shifting: Agile For AllAgile Mindset Shifting: Agile For All
Agile Mindset Shifting: Agile For All
 
The Executives Step-by-Step Guide to Leading a Large-Scale Agile Transformation
The Executives Step-by-Step Guide to Leading a Large-Scale Agile TransformationThe Executives Step-by-Step Guide to Leading a Large-Scale Agile Transformation
The Executives Step-by-Step Guide to Leading a Large-Scale Agile Transformation
 
今どきのアーキテクチャ設計戦略 - QCon Tokyo 2016
今どきのアーキテクチャ設計戦略 - QCon Tokyo 2016今どきのアーキテクチャ設計戦略 - QCon Tokyo 2016
今どきのアーキテクチャ設計戦略 - QCon Tokyo 2016
 
Modern Agile Management and Leadership
Modern Agile Management and LeadershipModern Agile Management and Leadership
Modern Agile Management and Leadership
 
Hook me UP ( React Hooks Introduction)
Hook me UP ( React Hooks Introduction)Hook me UP ( React Hooks Introduction)
Hook me UP ( React Hooks Introduction)
 
Custom-tailored Agility with the Agile Fluency™ Model
Custom-tailored Agility with the Agile Fluency™ ModelCustom-tailored Agility with the Agile Fluency™ Model
Custom-tailored Agility with the Agile Fluency™ Model
 
アジャイル開発を支えるアーキテクチャ設計とは
アジャイル開発を支えるアーキテクチャ設計とはアジャイル開発を支えるアーキテクチャ設計とは
アジャイル開発を支えるアーキテクチャ設計とは
 
サイボウズの生産性を高める生産性向上チームと開発文化
サイボウズの生産性を高める生産性向上チームと開発文化サイボウズの生産性を高める生産性向上チームと開発文化
サイボウズの生産性を高める生産性向上チームと開発文化
 
The Developer Experience
The Developer ExperienceThe Developer Experience
The Developer Experience
 
Foundations of the Scaled Agile Framework: Be Agile. Scale Up. Stay Lean. And...
Foundations of the Scaled Agile Framework: Be Agile. Scale Up. Stay Lean. And...Foundations of the Scaled Agile Framework: Be Agile. Scale Up. Stay Lean. And...
Foundations of the Scaled Agile Framework: Be Agile. Scale Up. Stay Lean. And...
 
アジャイルメトリクス実践ガイド
アジャイルメトリクス実践ガイドアジャイルメトリクス実践ガイド
アジャイルメトリクス実践ガイド
 
Hexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootHexagonal architecture with Spring Boot
Hexagonal architecture with Spring Boot
 
Agile Transformation v1.27
Agile Transformation v1.27Agile Transformation v1.27
Agile Transformation v1.27
 

More from Hock Leng PUAH

ASP.net Image Slideshow
ASP.net Image SlideshowASP.net Image Slideshow
ASP.net Image Slideshow
Hock Leng PUAH
 
Visual basic asp.net programming introduction
Visual basic asp.net programming introductionVisual basic asp.net programming introduction
Visual basic asp.net programming introduction
Hock Leng PUAH
 
Using iMac Built-in Screen Sharing
Using iMac Built-in Screen SharingUsing iMac Built-in Screen Sharing
Using iMac Built-in Screen Sharing
Hock Leng PUAH
 
Hosting SWF Flash file
Hosting SWF Flash fileHosting SWF Flash file
Hosting SWF Flash file
Hock Leng PUAH
 
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in functions date( ) and mktime( ) to calculate age from date of birthPHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
Hock Leng PUAH
 
PHP built-in function mktime example
PHP built-in function mktime examplePHP built-in function mktime example
PHP built-in function mktime example
Hock Leng PUAH
 
A simple php exercise on date( ) function
A simple php exercise on date( ) functionA simple php exercise on date( ) function
A simple php exercise on date( ) function
Hock Leng PUAH
 
Integrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web siteIntegrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web site
Hock Leng PUAH
 
Responsive design
Responsive designResponsive design
Responsive design
Hock Leng PUAH
 
Step by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visibleStep by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visible
Hock Leng PUAH
 
Beautiful web pages
Beautiful web pagesBeautiful web pages
Beautiful web pages
Hock Leng PUAH
 
CSS Basic and Common Errors
CSS Basic and Common ErrorsCSS Basic and Common Errors
CSS Basic and Common ErrorsHock Leng PUAH
 
Connectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe ProjectConnectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe Project
Hock Leng PUAH
 
Logic gate lab intro
Logic gate lab introLogic gate lab intro
Logic gate lab intro
Hock Leng PUAH
 
Ohm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallelOhm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallel
Hock Leng PUAH
 
Connections Exercises Guide
Connections Exercises GuideConnections Exercises Guide
Connections Exercises Guide
Hock Leng PUAH
 
Design to circuit connection
Design to circuit connectionDesign to circuit connection
Design to circuit connection
Hock Leng PUAH
 
NMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 SummaryNMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 Summary
Hock Leng PUAH
 
Virtualbox step by step guide
Virtualbox step by step guideVirtualbox step by step guide
Virtualbox step by step guide
Hock Leng PUAH
 
Nms chapter 01
Nms chapter 01Nms chapter 01
Nms chapter 01
Hock Leng PUAH
 

More from Hock Leng PUAH (20)

ASP.net Image Slideshow
ASP.net Image SlideshowASP.net Image Slideshow
ASP.net Image Slideshow
 
Visual basic asp.net programming introduction
Visual basic asp.net programming introductionVisual basic asp.net programming introduction
Visual basic asp.net programming introduction
 
Using iMac Built-in Screen Sharing
Using iMac Built-in Screen SharingUsing iMac Built-in Screen Sharing
Using iMac Built-in Screen Sharing
 
Hosting SWF Flash file
Hosting SWF Flash fileHosting SWF Flash file
Hosting SWF Flash file
 
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in functions date( ) and mktime( ) to calculate age from date of birthPHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
 
PHP built-in function mktime example
PHP built-in function mktime examplePHP built-in function mktime example
PHP built-in function mktime example
 
A simple php exercise on date( ) function
A simple php exercise on date( ) functionA simple php exercise on date( ) function
A simple php exercise on date( ) function
 
Integrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web siteIntegrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web site
 
Responsive design
Responsive designResponsive design
Responsive design
 
Step by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visibleStep by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visible
 
Beautiful web pages
Beautiful web pagesBeautiful web pages
Beautiful web pages
 
CSS Basic and Common Errors
CSS Basic and Common ErrorsCSS Basic and Common Errors
CSS Basic and Common Errors
 
Connectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe ProjectConnectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe Project
 
Logic gate lab intro
Logic gate lab introLogic gate lab intro
Logic gate lab intro
 
Ohm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallelOhm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallel
 
Connections Exercises Guide
Connections Exercises GuideConnections Exercises Guide
Connections Exercises Guide
 
Design to circuit connection
Design to circuit connectionDesign to circuit connection
Design to circuit connection
 
NMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 SummaryNMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 Summary
 
Virtualbox step by step guide
Virtualbox step by step guideVirtualbox step by step guide
Virtualbox step by step guide
 
Nms chapter 01
Nms chapter 01Nms chapter 01
Nms chapter 01
 

Recently uploaded

The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
What is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptxWhat is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptx
christianmathematics
 
MERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDFMERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDF
scholarhattraining
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 

Recently uploaded (20)

The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
What is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptxWhat is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptx
 
MERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDFMERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDF
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 

Revision exercises on loop

  • 1. Revision Exercises on “Loops”
  • 2. while loop for loop do while Vs while loops Agenda
  • 4. while loop inti = 0; while (i < 101) { // Processing : i++; // at the end }
  • 5. Write a while loop to solve the following problem Annie has $0 at the start, she saves $300 per month. What will she save after 24 months? Exercise 1
  • 6. How many variables we need? saving (start from 0) month (start from 1) savingPerMth = 300 Problem solving: variables?
  • 7. int saving = 0; int month = 1; intsavingPerMth = 300; while (month <= 24) { saving = saving + savingPerMth; // saving += savingPerMth month++; } Console.WriteLine(“Total saving = ” + saving.ToString() ); Possible solution
  • 8. Write a while loop to solve the following problem John has $300 at the start, she saves $100 per month. For every 6 months after he gets his bonuses, he saves extra $500. What will he save after 12 months? Exercise 2
  • 9. int saving = 300; int month = 1; intsavingPerMth = 100; int bonus = 500; while (month <= 12) { saving += savingPerMth; // saving += savingPerMth if ( (month%6) == 0) { saving += bonus; } month++; } Console.WriteLine(“Total saving = ” + saving.ToString() ); Possible solution
  • 10. for loop for (inti=0; i < 101; i++ ) { // Processing }
  • 11. Write a while loop to solve the following problem Annie has $0 at the start, she saves $300 per month. What will she save after 24 months? Exercise 1 using for loop
  • 12. int saving = 0; intsavingPerMth = 300; for (int month=1; month<=24; month++) { saving += savingPerMth; } Console.WriteLine(“Total saving = ” + saving.ToString() ); Possible solution
  • 13. Write a while loop to solve the following problem John has $300 at the start, she saves $100 per month. For every 6 months after he gets his bonuses, he saves extra $500. What will he save after 12 months? Exercise 2 using for loop
  • 14. int saving = 300; intsavingPerMth = 100; int bonus = 500; for (int month=1; month<=12; month++) { saving += savingPerMth; if ( (month%6) == 0) { saving += bonus; } } Console.WriteLine(“Total saving = ” + saving.ToString() ); Possible solution
  • 15. a) write a for loop to output 0 to 10 b) write a for loop to output 10, 8, 6, 4, 2 and 0 Exercise 3 using for loop
  • 16. a) for (int x = 0; x <=10; x++) { Console.WriteLine( x.ToString() ); } b) for (int x = 10; x >=0; x = x -2) { Console.WriteLine( x.ToString() ); } Possible solution
  • 17. do loop do { } while ( ); // End condition // The difference between the "while" and "do while" loops is that the code in a do while loop will get executed at least once, because its while part is at the end.