Looping statement in vb.net

16,082 views

Published on

0 Comments
16 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
16,082
On SlideShare
0
From Embeds
0
Number of Embeds
134
Actions
Shares
0
Downloads
0
Comments
0
Likes
16
Embeds 0
No embeds

No notes for slide

Looping statement in vb.net

  1. 1. LOOPING STATEMENTINVB.NET<br />1<br />Department of CE/IT<br />
  2. 2. Looping Statement<br />Loop 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 statements<br />While<br />Do<br />for<br />2<br />Department of CE/IT<br />
  3. 3. While <br />This loop executes a set of statements when a condition is true. The statement block is executed repeatedly until the condition becomes false.<br />3<br />Department of CE/IT<br />
  4. 4. Syntax <br /> While <condition><br />Statement<br />End while<br />4<br />Department of CE/IT<br />
  5. 5. Example <br />Dim n As Integer<br />N=0<br />While n<10<br /> MsgBox(“Welcome to Ustudy.in”)<br /> N=n+1<br />End While<br /> This program displays the word “Welcome to Ustudy.in “ 10 times.<br />5<br />Department of CE/IT<br />
  6. 6. Do Loop While<br />The 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. <br />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.<br />6<br />Department of CE/IT<br />
  7. 7. Syntax 1<br />Example:<br />Dim n As Integer<br />n=10<br />Do While (n<5)<br /> n=n+10<br />Loop<br />MsgBox(n)<br />Output: 10<br />Do While <condition><br />Statement block<br />Loop<br />7<br />Department of CE/IT<br />
  8. 8. Syntax 2<br />Example:<br />Dim n As Integer<br />n=10<br />Do<br /> n=n+10<br />Loop While (n<5)<br />MsgBox(n)<br />Output: 20<br /> Do<br />Statement block<br />Loop While <condition><br />8<br />Department of CE/IT<br />
  9. 9. Do loop until<br />This loop executes a block of statements repeatedly when the condition is false.<br />9<br />Department of CE/IT<br />
  10. 10. Syntax 1<br />Example:<br />Dim n As Integer<br />Do until n>5<br /> n=n+10<br />Loop<br />MsgBox (n)<br />Output: 10<br />Do until <condition><br />Statement block<br />Loop <br />10<br />Department of CE/IT<br />
  11. 11. Syntax 2<br />Do<br />Statement block<br />Loop until <condition><br />Example:<br />Dim n As Integer<br />Do<br /> n=n+10<br />Loop until n>5<br />MsgBox (n)<br />Output: 20<br />11<br />Department of CE/IT<br />
  12. 12. For loop<br />The 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.<br />12<br />Department of CE/IT<br />
  13. 13. Syntax <br /> For index=start to end[Step step][statements][Exit For][statements]Next[index]<br />13<br />Department of CE/IT<br />
  14. 14. Example <br />For i=1 to 10<br />MsgBox (“Work hard God will stand by you”)<br />Next<br />The program display the string at 10 times<br />14<br />Department of CE/IT<br />
  15. 15. The End.<br />… THANK U …<br />15<br />Department of CE/IT<br />

×