SlideShare a Scribd company logo
3
Most read
5
Most read
20
Most read
Chapter 6C# .NET Loops
What will you be learning?For loopsWhile loopsDo loops
What is a loop?A loop is a way to execute a piece of code repeatedly Go round and round until an end condition is met
Why use loops?Eg: you need to add from 0 to 10   Solution not using loop:int answer;     answer = 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10; The above solution not suitable for very large numbers (says from 0 to 10000) – programmers are lazy, what would be a faster way to solve?
Flowchart “for” loopStart with i = 0End when i is not < 101Update i by adding 1
for loopfor (      )   // start, end, update conditions{    // Processing}
for loopfor (inti=0;  i < 101;  i++  )  {    // Processing}
for (inti=0;  i < 101;  i++  )  Write syntax of the following for loopsFrom j = 10 until j = 1000 (inclusive), update j by 1 for each loopFrom t = 2 until t = 1000 (inclusive), update t by 2 for each loopFrom m = 5 until m = 0 (inclusive), update m by -1 for each loop
Exercise Part 1 – For LoopsAdd a new project to “Part 1 For Loops”Put one button and add the following codes for its click method (pg 112):
Exercise Part 1 – For Loops
Exercise Part 2Loop Start Values and Loop End Values Add a project “Part 2” to the solution
Do it yourself - TimeTableModify the previous projectTo add item to the listBox:       listBox1.Items.Add("xxxx")To clear the listBox:       listBox1.Items.Clear( );
break     continueAdd new project to SpfChapter6 solution: “Extra – break and continue”Add a button and add codes into its Click method: for (int x=0; x < 11; x++){   if (x==5) break;MessageBox.Show(“x =”+x);}
break     continuefor (int x=0; x < 11; x++){   if (x==5) continue;MessageBox.Show(“x =”+x);}
while loopwhile (   ) // End condition {}
while loopinti = 0;while (i < 101){// Processing   :i++;  // at the end}
do loopdo{} while (   );    // End condition// The difference between the while(){.. } and Do {..} while(); loops is that the code in a Do loop will get executed at least once, because its while part is at the end.
do loopinti = 0;do{// Processing   :i++;  // at the end} while (i < 101);
Part 3Modify the previous projectChange from "for" loop to “while” and then to "do while" loop
SummaryA loop is a way to execute a piece of code repeatedly We shall be using loops again when we cover ArraysThere is also "foreach" loop that applies for string, array and objects

More Related Content

PDF
MG6088 SOFTWARE PROJECT MANAGEMENT
PPT
Uml class-diagram
PPT
MIS-CH04: Ethical and Social Issues in INformation Systems
PDF
Towards Greatness
PDF
Introduction to ibm pc assembly language
PPTX
Introduction to React JS for beginners | Namespace IT
PPTX
Oscillation 2017
PPTX
Big data
MG6088 SOFTWARE PROJECT MANAGEMENT
Uml class-diagram
MIS-CH04: Ethical and Social Issues in INformation Systems
Towards Greatness
Introduction to ibm pc assembly language
Introduction to React JS for beginners | Namespace IT
Oscillation 2017
Big data

What's hot (20)

PPT
Java Tutorial
PDF
Methods in Java
PPTX
Control structures in java
PPTX
Interface in java ,multiple inheritance in java, interface implementation
PDF
Insecure coding in C (and C++)
PPT
Java operators
PPTX
Introduction to php
PPSX
Exception Handling
PPT
C# Exceptions Handling
PPT
Inheritance and Polymorphism
PPT
C# basics
PPT
PHP - Introduction to File Handling with PHP
PPTX
Python basics
PPTX
Ch 04 asp.net application
PPTX
Loops PHP 04
PDF
Object-oriented Programming-with C#
PPSX
Javascript variables and datatypes
PPTX
Operators in java
PPTX
Java Tutorial
Methods in Java
Control structures in java
Interface in java ,multiple inheritance in java, interface implementation
Insecure coding in C (and C++)
Java operators
Introduction to php
Exception Handling
C# Exceptions Handling
Inheritance and Polymorphism
C# basics
PHP - Introduction to File Handling with PHP
Python basics
Ch 04 asp.net application
Loops PHP 04
Object-oriented Programming-with C#
Javascript variables and datatypes
Operators in java
Ad

Viewers also liked (9)

PPTX
C# looping basic
PPTX
Flow Control (C#)
PPTX
Do While and While Loop
PDF
Dr archana dhawan bajaj - csharp fundamentals slides
PPTX
Presentation on nesting of loops
PPTX
Switch case and looping
PPTX
Loops in C Programming
PPTX
While , For , Do-While Loop
PPT
Flow & Error Control
C# looping basic
Flow Control (C#)
Do While and While Loop
Dr archana dhawan bajaj - csharp fundamentals slides
Presentation on nesting of loops
Switch case and looping
Loops in C Programming
While , For , Do-While Loop
Flow & Error Control
Ad

Similar to C# Loops (20)

PPTX
C# Loops
PPTX
Module-1.pptxbdjdhcdbejdjhdbchchchchchjcjcjc
PPTX
lab-8 (1).pptx
PPTX
9. Asymptotic Analysizbbsbsbsbshzhsbbss.pptx
DOCX
Implementasi Pemodelan Sistem Ke TeeChart 2
DOCX
C++ Loops General Discussion of Loops A loop is a.docx
PDF
04-Looping( For , while and do while looping) .pdf
PPTX
Iterative control structures, looping, types of loops, loop working
PPTX
C++ loop
PDF
The Ring programming language version 1.8 book - Part 84 of 202
PDF
The Ring programming language version 1.6 book - Part 184 of 189
PDF
DSA 103 Object Oriented Programming :: Week 3
PDF
LOOPS TOPIC FOR CLASS XI PYTHON SYLLABUS
PPTX
Cs1123 6 loops
PDF
CH05.pdf
PPT
Introduction to Computer Programming and Utilization
PPTX
Object oriented programming system with C++
DOCX
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
PDF
C++ control structure
PPTX
Python programing
C# Loops
Module-1.pptxbdjdhcdbejdjhdbchchchchchjcjcjc
lab-8 (1).pptx
9. Asymptotic Analysizbbsbsbsbshzhsbbss.pptx
Implementasi Pemodelan Sistem Ke TeeChart 2
C++ Loops General Discussion of Loops A loop is a.docx
04-Looping( For , while and do while looping) .pdf
Iterative control structures, looping, types of loops, loop working
C++ loop
The Ring programming language version 1.8 book - Part 84 of 202
The Ring programming language version 1.6 book - Part 184 of 189
DSA 103 Object Oriented Programming :: Week 3
LOOPS TOPIC FOR CLASS XI PYTHON SYLLABUS
Cs1123 6 loops
CH05.pdf
Introduction to Computer Programming and Utilization
Object oriented programming system with C++
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
C++ control structure
Python programing

More from Hock Leng PUAH (20)

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

Recently uploaded (20)

PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Cell Types and Its function , kingdom of life
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Institutional Correction lecture only . . .
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Basic Mud Logging Guide for educational purpose
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Business Ethics Teaching Materials for college
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Cell Types and Its function , kingdom of life
STATICS OF THE RIGID BODIES Hibbelers.pdf
Institutional Correction lecture only . . .
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Basic Mud Logging Guide for educational purpose
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
FourierSeries-QuestionsWithAnswers(Part-A).pdf
O7-L3 Supply Chain Operations - ICLT Program
Anesthesia in Laparoscopic Surgery in India
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPH.pptx obstetrics and gynecology in nursing
Complications of Minimal Access Surgery at WLH
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Microbial diseases, their pathogenesis and prophylaxis
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Supply Chain Operations Speaking Notes -ICLT Program
human mycosis Human fungal infections are called human mycosis..pptx
Business Ethics Teaching Materials for college

C# Loops

  • 2. What will you be learning?For loopsWhile loopsDo loops
  • 3. What is a loop?A loop is a way to execute a piece of code repeatedly Go round and round until an end condition is met
  • 4. Why use loops?Eg: you need to add from 0 to 10 Solution not using loop:int answer; answer = 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10; The above solution not suitable for very large numbers (says from 0 to 10000) – programmers are lazy, what would be a faster way to solve?
  • 5. Flowchart “for” loopStart with i = 0End when i is not < 101Update i by adding 1
  • 6. for loopfor ( ) // start, end, update conditions{ // Processing}
  • 7. for loopfor (inti=0; i < 101; i++ ) { // Processing}
  • 8. for (inti=0; i < 101; i++ ) Write syntax of the following for loopsFrom j = 10 until j = 1000 (inclusive), update j by 1 for each loopFrom t = 2 until t = 1000 (inclusive), update t by 2 for each loopFrom m = 5 until m = 0 (inclusive), update m by -1 for each loop
  • 9. Exercise Part 1 – For LoopsAdd a new project to “Part 1 For Loops”Put one button and add the following codes for its click method (pg 112):
  • 10. Exercise Part 1 – For Loops
  • 11. Exercise Part 2Loop Start Values and Loop End Values Add a project “Part 2” to the solution
  • 12. Do it yourself - TimeTableModify the previous projectTo add item to the listBox: listBox1.Items.Add("xxxx")To clear the listBox: listBox1.Items.Clear( );
  • 13. break continueAdd new project to SpfChapter6 solution: “Extra – break and continue”Add a button and add codes into its Click method: for (int x=0; x < 11; x++){ if (x==5) break;MessageBox.Show(“x =”+x);}
  • 14. break continuefor (int x=0; x < 11; x++){ if (x==5) continue;MessageBox.Show(“x =”+x);}
  • 15. while loopwhile ( ) // End condition {}
  • 16. while loopinti = 0;while (i < 101){// Processing :i++; // at the end}
  • 17. do loopdo{} while ( ); // End condition// The difference between the while(){.. } and Do {..} while(); loops is that the code in a Do loop will get executed at least once, because its while part is at the end.
  • 18. do loopinti = 0;do{// Processing :i++; // at the end} while (i < 101);
  • 19. Part 3Modify the previous projectChange from "for" loop to “while” and then to "do while" loop
  • 20. SummaryA loop is a way to execute a piece of code repeatedly We shall be using loops again when we cover ArraysThere is also "foreach" loop that applies for string, array and objects