Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Principles of Software Design and Development LOOPS / REPITITION.

Similar presentations


Presentation on theme: "1 Principles of Software Design and Development LOOPS / REPITITION."— Presentation transcript:

1 1 Principles of Software Design and Development LOOPS / REPITITION

2 2 Aims  Recap the use of loops – While & Do  Look at the format of the For…Next Loop  How can we use the For loop?  The use of STEP  Questions

3 RECAP Dim Counter as Integer Counter = 1 Do While Counter < 10 Counter = Counter + 1 Loop Dim Counter as Integer Counter = 1 Do Counter = Counter + 1 Loop Until Counter > 10

4 Btec National - Principles of Software Development 4 The For…Next Loop For the loop to work we need to know three things…  When the loop will start.  When the loop will end.  Where the loop is up to at a given point. Washing the dishes… Dim TotalNoOfDishes as Integer Dim CurrentDishNo as Integer TotalNoOfDishes = 10 For CurrentDishNo = 1 To TotalNoOfDishes ‘wash a dish Next

5 Btec National - Principles of Software Development 5 The For…Next Loop  The basic syntax for a ‘For loop’ is:   For = To  For = To  ‘Execute code statements  Next  Next

6 Btec National - Principles of Software Development 6 The For…Next Loop  Dim valFrom As Integer = txtFrom.Text  Dim valTo As Integer = txtTo.Text  Dim count As Integer  For count = valFrom To valTo  lstTest.Items.Add(count)  Next

7 The Use of STEP For Counter = 1 to 5 Step 2 'code here Next Would loop three times, through the values 1, 3 and 5. Step forces the loop (in this example) to make increments of 2. What does the following code do?... For Counter = 5 to 1 Step -1 'code here Next

8 Questions 1.Complete the code for the following For Next loop so that it starts with a value of 1 and ends with 10: Dim Counter as Integer For Counter = _____ To _____ 'code here Next

9 Questions What will be the value of Temp? Dim StartValue As Integer Dim StartValue As Integer Dim EndValue As Integer Dim EndValue As Integer Dim Counter As Integer Dim Counter As Integer Dim Temp As Integer Dim Temp As Integer StartValue = 10 StartValue = 10 EndValue = StartValue * 2 EndValue = StartValue * 2 Temp = 0 Temp = 0 For Counter = StartValue To EndValue For Counter = StartValue To EndValue Temp = Temp + 1 Temp = Temp + 1 Next Next

10 Questions  3. Write a For Next Loop that counts from 50 to 200.  4. Write a For Next Loop that counts from 10 to 0 in steps of 2


Download ppt "1 Principles of Software Design and Development LOOPS / REPITITION."

Similar presentations


Ads by Google