Wednesday, January 9, 2013

Visuel Basic:Loop

Do...Loop:

Used to execute a block of statements an unspecified number of times.

Do While condition
     statements
Loop

First, the condition is tested; if condition is True, then the statements are executed. When it gets to the Loop it goes back to the Do and tests condition again. If condition is False on the first pass, the statements are never executed.




For...Next:

When the number of iterations of the loop is known, it is better to use the For...Next rather than the Do...Loop.

For counter = start To end
     statements
Next

1) The counter is set to the value of start.
2) Counter is checked to see if it is greater than end; if yes, control passes to the statement after the Next; if not the statements are executed.
3)At Next, counter is incremented and goes back to step 2).

0 comments:

Post a Comment

Powered by Blogger.