ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
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

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