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

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 

Recently uploaded (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
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
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
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
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 

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