Results 1 to 10 of 10

Thread: visual basic helppp loops

  1. #1
    Join Date
    18 Jun 2010
    Location
    karachi
    Age
    33
    Gender
    Male
    Posts
    344
    Threads
    80
    Credits
    8
    Thanked
    22

    Default visual basic helppp loops

    every one!
    kisi k pas for lop, while lop, do lop, nested lop ki examples hain jin ko krne se loops theak tarah se samjh a jain plz output k sath shair kr dian thanks

  2. #2
    Haseeb Alamgir's Avatar
    Haseeb Alamgir is offline Super Moderator
    Last Online
    Yesterday @ 08:18 PM
    Join Date
    09 Apr 2009
    Location
    KARACHI&
    Gender
    Male
    Posts
    19,381
    Threads
    419
    Credits
    39,864
    Thanked
    1813

    Default

    Do { While | Until } condition
    [ statements ]
    [ Exit Do ]
    [ statements ]
    Loop
    -or-
    Do
    [ statements ]
    [ Exit Do ]
    [ statements ]
    Loop { While | Until } condition

  3. #3
    Haseeb Alamgir's Avatar
    Haseeb Alamgir is offline Super Moderator
    Last Online
    Yesterday @ 08:18 PM
    Join Date
    09 Apr 2009
    Location
    KARACHI&
    Gender
    Male
    Posts
    19,381
    Threads
    419
    Credits
    39,864
    Thanked
    1813

    Default

    Use a Do...Loop structure when you want to repeat a set of statements an indefinite number of times, until a condition is satisfied. If you want to repeat the statements a set number of times, the For...Next Statement is usually a better choice.

    The Do...Loop structure gives you more flexibility than the While...End While Statement (Visual Basic) because it allows you to choose whether to end the loop when condition stops being True or when it first becomes True. It also allows you to test condition at either the beginning or the end of the loop.
    Rules

    Nature of Condition. The condition usually results from a comparison of two values, but it can be any expression that evaluates to a Boolean Data Type (Visual Basic) value (True or False). This includes values of other data types, such as numeric types, that have been converted to Boolean.

    Testing the Condition. You can test condition only once, at either the beginning or the end of the loop. You can use either While or Until to specify condition, but not both.

    Number of Iterations. If you test condition at the beginning of the loop (in the Do statement), the loop might never run even once. If you test at the end of the loop (in the Loop statement), the loop always runs at least once.

    Nesting Loops. You can nest Do loops by placing one loop within another. You can also nest different kinds of control structures within one another. For more information, see Nested Control Structures.

    Transferring Out of the Loop. The Exit Statement (Visual Basic) transfers control immediately to the statement following the Loop statement. You might want to exit a loop if you detect a condition that makes it unnecessary or impossible to continue iterating, such as an erroneous value or a termination request. You can place any number of Exit Do statements anywhere in the Do loop. Exit Do is often used after evaluating some condition, for example in an If...Then...Else structure.

    Endless Loops

    One use of Exit Do is to test for a condition that could cause an endless loop, which is a loop that could run an extremely large or even infinite number of times. If you detect such a condition, you can use Exit Do to escape the loop. Otherwise, the loop continues running.

    In the following example, number is assigned a value that could cause the loop to run more than 2 ^ 31 times. The If statement checks for this condition and exits if it exists, preventing endless looping.

  4. #4
    Zeeshanef's Avatar
    Zeeshanef is offline Advance Member
    Last Online
    28th December 2023 @ 02:18 PM
    Join Date
    30 Mar 2006
    Location
    Great Pakistan
    Gender
    Male
    Posts
    846
    Threads
    12
    Credits
    1,456
    Thanked
    46

    Default

    Google per ya MSDN per aapko Loops aor nested lopps ki hazaron examples mil jaa'in gi.
    Agar aap koi kisi particular cheez ke baray mein ja'na chahtay hain to wo likhain, shukriya.

  5. #5
    Haseeb Alamgir's Avatar
    Haseeb Alamgir is offline Super Moderator
    Last Online
    Yesterday @ 08:18 PM
    Join Date
    09 Apr 2009
    Location
    KARACHI&
    Gender
    Male
    Posts
    19,381
    Threads
    419
    Credits
    39,864
    Thanked
    1813

    Default

    Sub exitDoExample()
    Dim counter As Integer = 0
    Dim number As Integer = 8
    Do Until number = 10
    If number <= 0 Then Exit Do
    number -= 1
    counter += 1
    Loop
    MsgBox("The loop ran " & counter & " times.")
    End Sub

  6. #6
    Haseeb Alamgir's Avatar
    Haseeb Alamgir is offline Super Moderator
    Last Online
    Yesterday @ 08:18 PM
    Join Date
    09 Apr 2009
    Location
    KARACHI&
    Gender
    Male
    Posts
    19,381
    Threads
    419
    Credits
    39,864
    Thanked
    1813

    Default

    While condition
    [ statements ]
    [ Exit While ]
    [ statements ]
    End While

  7. #7
    Haseeb Alamgir's Avatar
    Haseeb Alamgir is offline Super Moderator
    Last Online
    Yesterday @ 08:18 PM
    Join Date
    09 Apr 2009
    Location
    KARACHI&
    Gender
    Male
    Posts
    19,381
    Threads
    419
    Credits
    39,864
    Thanked
    1813

    Default

    Dim counter As Integer = 0
    While counter < 20
    counter += 1
    ' Insert code to use current value of counter.
    End While
    MsgBox("While loop ran " & CStr(counter) & " times")

  8. #8
    Haseeb Alamgir's Avatar
    Haseeb Alamgir is offline Super Moderator
    Last Online
    Yesterday @ 08:18 PM
    Join Date
    09 Apr 2009
    Location
    KARACHI&
    Gender
    Male
    Posts
    19,381
    Threads
    419
    Credits
    39,864
    Thanked
    1813

    Default

    Use a While...End While structure when you want to repeat a set of statements an indefinite number of times, as long as a condition remains True. If you want more flexibility with where you test the condition or what result you test it for, you might prefer the Do...Loop Statement (Visual Basic). If you want to repeat the statements a set number of times, the For...Next Statement (Visual Basic) is usually a better choice.

    If condition is True, all of the statements run until the End While statement is encountered. Control then returns to the While statement and condition is again checked. If condition is still True, the process is repeated. If it is False, control passes to the statement following the End While statement.

  9. #9
    Join Date
    18 Jun 2010
    Location
    karachi
    Age
    33
    Gender
    Male
    Posts
    344
    Threads
    80
    Credits
    8
    Thanked
    22

    Default

    thankss

  10. #10
    IT.BOY's Avatar
    IT.BOY is offline Senior Member
    Last Online
    17th November 2017 @ 12:13 PM
    Join Date
    26 Dec 2007
    Location
    *MAA KI AGOOSH*
    Gender
    Male
    Posts
    28,374
    Threads
    651
    Credits
    998
    Thanked
    3079

    Default

    [FONT="Jameel Noori Nastaleeq"][CENTER][COLOR="Blue"][SIZE="5"][B]Coming Soon...:)[/B][/SIZE][/COLOR][/CENTER][/FONT]

Similar Threads

  1. Replies: 11
    Last Post: 6th May 2022, 06:16 PM
  2. Visual Basic Mai Kiasay Mai Database Connect Karo?
    By MOHAMMEDALI1989 in forum Ask an Expert
    Replies: 3
    Last Post: 1st November 2011, 08:24 PM
  3. Visual Basic Books for beginners, advance and professional users
    By Mubashar_ali in forum General Discussion
    Replies: 10
    Last Post: 26th September 2011, 06:54 PM
  4. Replies: 4
    Last Post: 14th June 2010, 12:28 AM
  5. visual basic help urgent
    By don_log in forum Ask an Expert
    Replies: 2
    Last Post: 28th December 2009, 08:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •