Monday, November 10, 2008

vb loop concept

A For...Next loop condition can be terminated by an Exit For statement. Consider the following statement block.

Dim x As IntegerFor x = 1 To 10Print xIf x = 5 ThenPrint "The program exited at x=5"End IfNext
The preceding code increments the value of x by 1 until it reaches the condition x = 5. The Exit For statement is executed and it terminates the For...Next loop. The Following statement block containing Do...While loop is terminated using Exit Do statement.
Dim x As IntegerDo While x < 10Print xx = x + 1If x = 5 ThenPrint "The program is exited at x=5"Exit DoEnd IfLoop

No comments: