Control Structures: Using Loops
Control Structures: Using Loops
NET
CONTROL STRUCTURES
PART 2
Using Loops
Deterministic
The starting value and the stopping value is known.
Programmer knows exactly how many times the loop
needs to be executed
Undeterministic
The starting value is known but stopping value is
unknown
However, the condition for the loop to stop execution is
known
LOOP STRUCTURE 1
WHILE…END WHILE
Ctr = 1
False
DO WHILE LOOPS
DO…LOOP WHILE
Do
execute statement(s)
Loop While condition is True
A.P.I.I.T - Revised by Nadeera Ahangama 3/11/2009 1- 13
EX: DO WHILE…LOOP
n1 = 1
Do While n1 <= 10
ListBox1.Items.Add(n1)
n1 = n1 + 1
Loop
DO…LOOP UNTIL
Do
execute statement(s)
Loop Until condition becomes True
False
Ctr > 10
True
FOR … NEXT
ITERATIVE CONSTRUCT
Dim n1 as integer
For n1 = 1 To 10 Step 2
ListBox1.Items.Add(n1)
Next n1
End Sub
End Class
*
* *
* * *
* * * *
* * * * *
A.P.I.I.T - Revised by Nadeera Ahangama 3/11/2009 1- 37