Looping
Loop is a looping technique where the programmer can repeat the command line in the source code as many times as desired. There are several known recurrence in the Visual Basic.Net language, among others:
• For - Next
Repetition is used when there is a repeated command line, and the number of repetitions has been known with certainty.
Syntax:
For variable = initvalue to maxvalue step increment / decrement
Statement for loop
[Exit For]
Next
Step is optional means can be written or not. If not written the default step value is 1. Step is used to increase the value of a variable each time the statement in the for-next repeat. Exit for a way to force out of the loop (optional).
Example: Repetition of the smallest value to largest value
Dim I as integer
For i = 0 to 20 [step 1]
Console.write (i)
Next
Repetition of the greatest value to the smallest value
For I as integer = 20 to 0 step -1
Console.write (i)
Next
Variables can also be directly declared in the for-next relevant as the above example. These variables will be local only for identified on the next.
• Do while - loop
Repetition is used if the number does not necessarily iterasinya. Usually the loop will be finished when found one or several conditions. Loop will be completed if the conditions mentioned in the false worth while.
Syntax:
Do while condition
Statement for loop
[Exit Do]
Loop
Repetition will check the condition before starting the iteration. If the initial condition is not met, then the iteration can not be done at all.
Example:
Dim I as integer = 1
Do while i <5 integer =" 1"> 5
Console.writeline (i)
I + = 1
Loop
• Do - loop while
Almost equal to do while - loops, but the condition will be checked at the end of the loop, so that if the initial condition one, the command line in the loop will still be done once before out of the loop.
Syntax:
Do
Statement for loop
[Exit Do]
Loop while condition
Repetition is a condition check is done once after recurrence. If the initial condition is not met, then the statements inside the loop will only be done once.
Example:
Dim I as integer = 1
Do
Console.writeline (i)
I + = 1
Loop while (i<=5)
• While - end while
This form exactly do while - loops, only suffixes and how to get out of his force from the loop are different. Structure and flow in exactly the same.
Syntax:
While condition
Statement for loop
[Exit While]
End while
Example:
Dim I as integer = 1
While i <5
Console.writeline (i)
I + = 1
End while
Currently have 0 komentar: