Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Loops

2,171 views

Published on

  • Be the first to comment

  • Be the first to like this

Loops

  1. 1. LOOPS
  2. 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. 3. You Could Code The ‘Ha Ha’ Like ThisConsole.WriteLine("Ha Ha ")Console.WriteLine("Ha Ha ") But is actually Lame!Console.WriteLine("Ha Ha ") No good programmerConsole.WriteLine("Ha Ha ") does this!Console.WriteLine("Ha Ha ")Console.WriteLine("Ha Ha ")Console.WriteLine("Ha Ha ")Console.WriteLine("Ha Ha ")
  4. 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. 5. COUNTER = 0 The FOR Loop For as long as thecounter isn’t 8 carry FOR loops stop on when their counter runs out Console.WriteLine("Ha Ha ") COUNTER + 1
  6. 6. FOR Loops in VBModule Module1 Sub Main() Dim count As Integer For count = 1 To 8 Console.WriteLine("HA HA!") Next Console.ReadLine() End SubEnd Module
  7. 7. STOP = no The WHILE LoopWhile stop is still no carry on WHILE may never stop! Console.WriteLine("Ha Ha ") STOP = yes
  8. 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 SubEnd Module

×