Loop structuresThese are used when we want lines of codeto be executed many timesWe might want it to run a set number oftimes.We may need to check if various conditionshave been met.There are loops for all occasions andprogrammers have their “favourites”! 2
Fixed Loop structuresIf we want the loop to run a fixed numberof times, we use a For…..Next loopThis will use a variable as a counterSyntax: For first value To last value Line of code to execute Next value 3
Conditional Loop StructuresIf we want the loop to repeat until acondition changes (at runtime).Use While …. End While to check thecondition before running loopSyntax: While condition = true Line of code execute End While 5
Conditional Loop StructuresUse Do…. Loop to run until a conditionbecomes trueThis code will run at least once Beware! It is possible to create loops that carry on to infinity. Press Ctrl + Break to stop, but you may lose some unsaved workSyntax: Do Line of code to execute Loop Until condition = true 7
Programming termsWhen we need to repeat a set ofinstructions, we have 3 options: For….Next - runs for fixed number of loops While…End While - runs while condition is true Do…Loop Until - runs until condition becomes true 9
A particular slide catching your eye?
Clipping is a handy way to collect important slides you want to go back to later.