LOOPING STATEMENTINVB.NET1Department of CE/IT
Looping StatementLoop statements are used to execute a block of statements repeatedly. For example to execute a statement 100 times, it is not necessary to write the statement 100 times in the program. VB.NET supports 3 types of loop statementsWhileDofor2Department of CE/IT
While This loop executes a set of statements when a condition is true. The statement block is executed repeatedly until the condition becomes false.3Department of CE/IT
Syntax While <condition>StatementEnd while4Department of CE/IT
Example Dim n As IntegerN=0While n<10 MsgBox(“Welcome to Ustudy.in”) N=n+1End While This program displays the word “Welcome to Ustudy.in “ 10 times.5Department of CE/IT
Do Loop WhileThe Do loop can be used to execute a fixed block of statements indefinite number of times. The Do loop keeps executing it's statements while or until the condition is true. Two keywords, while and until can be used with the do loop. The Do loop also supports an Exit Do statement which makes the loop to exit at any moment.6Department of CE/IT
Syntax 1Example:Dim n As Integern=10Do While (n<5) n=n+10LoopMsgBox(n)Output: 10Do While <condition>Statement blockLoop7Department of CE/IT
Syntax 2Example:Dim n As Integern=10Do n=n+10Loop While (n<5)MsgBox(n)Output: 20 DoStatement blockLoop While <condition>8Department of CE/IT
Do loop untilThis loop executes a block of statements repeatedly when the condition is false.9Department of CE/IT
Syntax 1Example:Dim n As IntegerDo until n>5 n=n+10LoopMsgBox (n)Output: 10Do until <condition>Statement blockLoop 10Department of CE/IT
Syntax 2DoStatement blockLoop until <condition>Example:Dim n As IntegerDo n=n+10Loop until n>5MsgBox (n)Output: 2011Department of CE/IT
For loopThe For loop is the most popular loop. For loops enable us to execute a series of expressions multiple numbers of times. The For loop in VB .NET needs a loop index which counts the number of loop iterations as the loop executes.12Department of CE/IT
Syntax For index=start to end[Step step][statements][Exit For][statements]Next[index]13Department of CE/IT
Example For i=1 to 10MsgBox (“Work hard God will stand by you”)NextThe program display the string at 10 times14Department of CE/IT
The End.… THANK U …15Department of CE/IT

Looping statement in vb.net

  • 1.
  • 2.
    Looping StatementLoop statementsare used to execute a block of statements repeatedly. For example to execute a statement 100 times, it is not necessary to write the statement 100 times in the program. VB.NET supports 3 types of loop statementsWhileDofor2Department of CE/IT
  • 3.
    While This loopexecutes a set of statements when a condition is true. The statement block is executed repeatedly until the condition becomes false.3Department of CE/IT
  • 4.
    Syntax While <condition>StatementEnd while4Department of CE/IT
  • 5.
    Example Dim nAs IntegerN=0While n<10 MsgBox(“Welcome to Ustudy.in”) N=n+1End While This program displays the word “Welcome to Ustudy.in “ 10 times.5Department of CE/IT
  • 6.
    Do Loop WhileTheDo loop can be used to execute a fixed block of statements indefinite number of times. The Do loop keeps executing it's statements while or until the condition is true. Two keywords, while and until can be used with the do loop. The Do loop also supports an Exit Do statement which makes the loop to exit at any moment.6Department of CE/IT
  • 7.
    Syntax 1Example:Dim nAs Integern=10Do While (n<5) n=n+10LoopMsgBox(n)Output: 10Do While <condition>Statement blockLoop7Department of CE/IT
  • 8.
    Syntax 2Example:Dim nAs Integern=10Do n=n+10Loop While (n<5)MsgBox(n)Output: 20 DoStatement blockLoop While <condition>8Department of CE/IT
  • 9.
    Do loop untilThisloop executes a block of statements repeatedly when the condition is false.9Department of CE/IT
  • 10.
    Syntax 1Example:Dim nAs IntegerDo until n>5 n=n+10LoopMsgBox (n)Output: 10Do until <condition>Statement blockLoop 10Department of CE/IT
  • 11.
    Syntax 2DoStatement blockLoopuntil <condition>Example:Dim n As IntegerDo n=n+10Loop until n>5MsgBox (n)Output: 2011Department of CE/IT
  • 12.
    For loopThe Forloop is the most popular loop. For loops enable us to execute a series of expressions multiple numbers of times. The For loop in VB .NET needs a loop index which counts the number of loop iterations as the loop executes.12Department of CE/IT
  • 13.
    Syntax Forindex=start to end[Step step][statements][Exit For][statements]Next[index]13Department of CE/IT
  • 14.
    Example For i=1to 10MsgBox (“Work hard God will stand by you”)NextThe program display the string at 10 times14Department of CE/IT
  • 15.
    The End.… THANKU …15Department of CE/IT