Today: Looping - Part 1
Today: Looping - Part 1
20S
Loop Action
Next Action
Loops (cont’d)
Each repetition of the loop is usually controlled
by the outcome of a conditional statement
which will evaluate to true or false
Then inside the body of the loop, something
will occur that may (or may not) cause the testing
condition to evaluate differently the next time
through the loop
Once the condition evaluates to false the loop is
exited and the next statement following the loop
is executed
Loops (cont’d)
Loops can occur in two ways:
Event controlled loops are used when
you don’t know when to stop a loop (an
event – e.g. the end of a file) will trigger the
end of the loop
Count controlled loops are used when
you need to execute the loop a specific
number of times (e.g. X times)
Loops (cont’d)
The event controlled No
loop... Yes
Are you at
Stop when you
the end of
reach the end the file?
of the file..
Read Check
another again
piece of
the file
Notice that
like if
statements,
loops are
indented
1. Button (btnFind)
2. ComboBox (cboValues)
3. Label (lblMax)
4. ListBox (lstNumbers)
5. Label (lblDisplay)
Looping Example 1 (cont’d)
9/16/19