SlideShare a Scribd company logo
1 of 8
LOOPS
Very Often, You Will Want to Do
  Something More Than Once
          HA HA
          HA HA
          HA HA
          HA HA
          HA HA
          HA HA
You Could Code The ‘Ha Ha’ Like This
Console.WriteLine("Ha Ha ")
Console.WriteLine("Ha Ha ")   But is actually Lame!
Console.WriteLine("Ha Ha ")   No good programmer
Console.WriteLine("Ha Ha ")         does this!
Console.WriteLine("Ha Ha ")
Console.WriteLine("Ha Ha ")
Console.WriteLine("Ha Ha ")
Console.WriteLine("Ha Ha ")
Loops To The Rescue!
• A loop is a piece of code which allows you to
  repeat some code more than once without
  having to write it out more than once.
     Do that 8
      times!




                 Console.WriteLine("Ha Ha ")
COUNTER = 0          The FOR Loop
 For as long as the
counter isn’t 8 carry                               FOR loops stop
         on                                           when their
                                                   counter runs out




                            Console.WriteLine("Ha Ha ")




                         COUNTER + 1
FOR Loops in VB
Module Module1
    Sub Main()
        Dim count As Integer
        For count = 1 To 8
            Console.WriteLine("HA HA!")
        Next
        Console.ReadLine()
    End Sub
End Module
STOP = no           The WHILE Loop
While stop is still no
     carry on
                                                    WHILE may
                                                    never stop!



                              Console.WriteLine("Ha Ha ")




                           STOP = yes
Module Module1       WHILE Loops in VB
   Sub Main()
       Dim stopProgram As String

       stopProgram = "no"

       While stopProgram = "no"
           Console.WriteLine("HA HA!")
           Console.WriteLine("HA HA!")
           Console.WriteLine("HA HA!")

             Console.WriteLine("Do you want to stop?")
             stopProgram = Console.ReadLine()

       End While
       Console.WriteLine("GOODBYE!")
       Console.ReadLine()

   End Sub

End Module

More Related Content

Viewers also liked

Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
bsdeol28
 
Migliora l'efficienza della tua cella frigo
Migliora l'efficienza della tua cella frigoMigliora l'efficienza della tua cella frigo
Migliora l'efficienza della tua cella frigo
Davide Margelli
 
литературная карта
литературная карталитературная карта
литературная карта
mukcbs55
 
Presentacion diapositivas
Presentacion diapositivasPresentacion diapositivas
Presentacion diapositivas
6259874
 
о любви
о любвио любви
о любви
mukcbs55
 

Viewers also liked (19)

Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
 
Loops
LoopsLoops
Loops
 
Nesting of for loops using C++
Nesting of for loops using C++Nesting of for loops using C++
Nesting of for loops using C++
 
Flow charts
Flow chartsFlow charts
Flow charts
 
2 d autocad_2009
2 d autocad_20092 d autocad_2009
2 d autocad_2009
 
Java loops
Java loopsJava loops
Java loops
 
Silverlight
SilverlightSilverlight
Silverlight
 
Migliora l'efficienza della tua cella frigo
Migliora l'efficienza della tua cella frigoMigliora l'efficienza della tua cella frigo
Migliora l'efficienza della tua cella frigo
 
литературная карта
литературная карталитературная карта
литературная карта
 
Appency Mobile App Marketing (iPhone, Android, Windows, Blackberry)
Appency Mobile App Marketing (iPhone, Android, Windows, Blackberry)Appency Mobile App Marketing (iPhone, Android, Windows, Blackberry)
Appency Mobile App Marketing (iPhone, Android, Windows, Blackberry)
 
Darden school of business elective encourages entrepreneurship
Darden school of business elective encourages entrepreneurshipDarden school of business elective encourages entrepreneurship
Darden school of business elective encourages entrepreneurship
 
Hello world
Hello worldHello world
Hello world
 
Presentacion diapositivas
Presentacion diapositivasPresentacion diapositivas
Presentacion diapositivas
 
о любви
о любвио любви
о любви
 
Careers In English Literature
Careers In English LiteratureCareers In English Literature
Careers In English Literature
 
Budgeting for the future :)
Budgeting for the future :)Budgeting for the future :)
Budgeting for the future :)
 
Ltr
LtrLtr
Ltr
 
Is numeric
Is numericIs numeric
Is numeric
 
Entity framework
Entity frameworkEntity framework
Entity framework
 

More from Peter Andrews (10)

Trimming text
Trimming textTrimming text
Trimming text
 
Splitting up text
Splitting up textSplitting up text
Splitting up text
 
Reading in files
Reading in filesReading in files
Reading in files
 
Syntax errors
Syntax errorsSyntax errors
Syntax errors
 
Arrays
ArraysArrays
Arrays
 
Rounding numbers
Rounding numbersRounding numbers
Rounding numbers
 
Select case
Select caseSelect case
Select case
 
If
IfIf
If
 
Collecting user input
Collecting user inputCollecting user input
Collecting user input
 
Variables
VariablesVariables
Variables
 

Recently uploaded

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 

Recently uploaded (20)

How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 

Loops

  • 2. Very Often, You Will Want to Do Something More Than Once HA HA HA HA HA HA HA HA HA HA HA HA
  • 3. You Could Code The ‘Ha Ha’ Like This Console.WriteLine("Ha Ha ") Console.WriteLine("Ha Ha ") But is actually Lame! Console.WriteLine("Ha Ha ") No good programmer Console.WriteLine("Ha Ha ") does this! Console.WriteLine("Ha Ha ") Console.WriteLine("Ha Ha ") Console.WriteLine("Ha Ha ") Console.WriteLine("Ha Ha ")
  • 4. Loops To The Rescue! • A loop is a piece of code which allows you to repeat some code more than once without having to write it out more than once. Do that 8 times! Console.WriteLine("Ha Ha ")
  • 5. COUNTER = 0 The FOR Loop For as long as the counter isn’t 8 carry FOR loops stop on when their counter runs out Console.WriteLine("Ha Ha ") COUNTER + 1
  • 6. FOR Loops in VB Module Module1 Sub Main() Dim count As Integer For count = 1 To 8 Console.WriteLine("HA HA!") Next Console.ReadLine() End Sub End Module
  • 7. STOP = no The WHILE Loop While stop is still no carry on WHILE may never stop! Console.WriteLine("Ha Ha ") STOP = yes
  • 8. Module Module1 WHILE Loops in VB Sub Main() Dim stopProgram As String stopProgram = "no" While stopProgram = "no" Console.WriteLine("HA HA!") Console.WriteLine("HA HA!") Console.WriteLine("HA HA!") Console.WriteLine("Do you want to stop?") stopProgram = Console.ReadLine() End While Console.WriteLine("GOODBYE!") Console.ReadLine() End Sub End Module