Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration in VB programming, requires the use of Looping Constructs There are 2 main types of Looping - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration in VB programming, requires the use of Looping Constructs There are 2 main types of Looping

Description:

Title: Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration in ... – PowerPoint PPT presentation

Number of Views:134
Avg rating:3.0/5.0
Slides: 14
Provided by: JHa4
Category:

less

Transcript and Presenter's Notes

Title: Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration in VB programming, requires the use of Looping Constructs There are 2 main types of Looping


1
Iteration (Looping Constructs in VB)Iteration
Groups of statements which are repeatedly
executed until a certain test is satisfied
Carrying out Iteration in VB programming,
requires the use of Looping ConstructsThere are
2 main types of Looping ConstructsDeterminate
Loops will repeat themselves a known (specific)
number of times (For..Next Loops)Indeterminate
Loops will repeat themselves an unknown number
of times (Do Loops) Until While
2
Determinate LoopsA group of statement is
repeated a specific number of times For..Next
LoopsRepeat the statements in a loop a specific
number of timesEach For statement has a
corresponding Next statementFor..Next Loop
syntax
For Counter/LoopIndex Start To End step
step Statements (Body of Loop) Next
Counter/LoopIndex
3
The For..Next loop uses the For and Next
statements and a Counter Variable
LoopIndexThe elements of a For..NextThe
Counter/LoopIndex must be a numeric variable,
determines the number of times the statements
inside the loop will be executedStart and End
may be Constants, Variables, Numeric Property
Values, or Numeric Expressions, and further
determine the initial and final value of the
counter The optional word Step may be included,
along with the value to be added to the LoopIndex
(positive/negative) for each iteration of the
loop, and if omitted, the default value is 1 for
each increment of the loop
4
Dim iLoopIndex As IntegerDim iMaximum As
IntegeriMaximum Inputbox(Enter the value,
Number of Entries)For iLoopIndex 0 To
iMaximum The statements inside of the loop are
indented, and referred to as the body of the
loopNext iLoopIndex
5
A Counter-Controlled Loop generally has 3
elementsInitialise the CounterIncrement the
Counter stepTest the Counter to determine when
it is time to Terminate the loopFor iIndex 2
To 100 Step 2will count from 2 to 100 by 2The
statements in the body of the loop will be
executed 50 times, with iIndex 2, 4, 6, .The
program checks for greater than the test value
and not equal to
6
Exiting For..Next LoopsIf you enter an Endless
Loop, the program execution will have to be
broken manuallyTherefore, you will need to
enter Break Time Ctrl BreakWith For..Next
loops, you may need to terminate the loop before
the loop index reaches its final valueVB
provides an Exit For statement for this
situationGenerally, an Exit For statement is
part of an If statement
7
For iLoopIndex 1 To 10 If txtInput.Text
Then nothing was entered into the input
textbox MsgBox You must enter something
Exit For End If . . statements in
the loopNext iLoopIndex
8
(No Transcript)
9
(No Transcript)
10
(No Transcript)
11
(No Transcript)
12
(No Transcript)
13
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com