Thursday, 17 February 2011

Loops

When using Visual Basic there are 3 different types of looping available to users:

1) For - Next
2) Do - While

3) Loop - Until

Every type of loop perform functions that are very similar.  They run one single piece of code many times, saving the programmer a lot of time.

For - Next

- Is used to run a piece of code a set number of times. As its name suggest, it is used when a function needs to be carried out FOR each of several items. The For...Next loop changes a variable every time it runs, so that the function can be specialised for each item.

 Do - While 
- Runs a piece of code if a condition is true. If the loop starts running, here must be a section inside the loop to either alter the condition or break out of the loop, otherwise it will run indefinitely. If the condition is initially false, the Do While loop does not run at all.

Loop - Until 
-  Is exactly the same as the Do While loop except that it will always run the code inside before checking whether the condition is true; that is, the code inside will always run at least once even if the condition is false.

1 comment:

  1. Very Nice.

    I look forward to testing the class on things like this.

    ReplyDelete