Difference between revisions of "Visual Basic For Loops"

From Techotopia
Jump to: navigation, search
(New page: Computers are incredibly good at repeating the same task over and over very quickly. One of the key functions of a programming language such as Visual Basic is to make it easy for a develo...)
 
(Creating a Visual Basic For Loop)
Line 5: Line 5:
 
The Visual Basic ''For'' loop is ideal for situations wheer a task needs to be performed a specific number of times. For example, perhaps a value needs to be added to a variable 100 times. A Visual Basic ''For'' loop consists of a header, a code block and a next statement. The header copntains information about how many time the loop is to be performed, the code block contains the statements to be executed on each iteration and the next statement sends the loop back to the header to repeat. The syntax of a ''For'' loop is as follows:
 
The Visual Basic ''For'' loop is ideal for situations wheer a task needs to be performed a specific number of times. For example, perhaps a value needs to be added to a variable 100 times. A Visual Basic ''For'' loop consists of a header, a code block and a next statement. The header copntains information about how many time the loop is to be performed, the code block contains the statements to be executed on each iteration and the next statement sends the loop back to the header to repeat. The syntax of a ''For'' loop is as follows:
  
<pre>
+
 
 
'''For''' ''counterVariable''
 
'''For''' ''counterVariable''

Revision as of 17:36, 6 August 2007

Computers are incredibly good at repeating the same task over and over very quickly. One of the key functions of a programming language such as Visual Basic is to make it easy for a developer to program a computer to perform these repetitive tasks. Visual Basic provides a number of language structures which which tell a program to perform a task repeatedlyt, either a specific number of times, or until certain conditions are met. In this chapter of Visual Basic essentials we will look at each of these in detail.

Creating a Visual Basic For Loop

The Visual Basic For loop is ideal for situations wheer a task needs to be performed a specific number of times. For example, perhaps a value needs to be added to a variable 100 times. A Visual Basic For loop consists of a header, a code block and a next statement. The header copntains information about how many time the loop is to be performed, the code block contains the statements to be executed on each iteration and the next statement sends the loop back to the header to repeat. The syntax of a For loop is as follows:


For counterVariable