Results 1 to 2 of 2

Thread: Loops need some help

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    14

    Question Loops need some help

    Hi everyone

    I'm slowly learning about loops.

    I have a couple of questions
    1) When a condition is being tested.. what does that mean? I don't understand the "condition" word.
    2) What is the difference between a loop that never ends and a loop that ends?

    I have the code for the loop that ends and the loop that never ends. I can see the difference in the code, but I don't understand what is making it different. Here is the code below.

    Dim intCount = 0
    Do While intCount <= 1
    MsgBox("This loop ends")
    intCount += 1
    Loop

    Dim intCount = 0
    Do While intCount <= 1
    MsgBox("This loop never ends")
    Loop

    Thanks heaps.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Loops need some help

    1. A "condition" is an expression that evaluates to a Boolean value, i.e. either True or False. That would include any comparison, e.g. (x = 0) or (myDate > Date.Today).

    2. An infinite loop is one that itself includes no condition for ending. For example, this is an infinite loop:
    vb.net Code:
    1. Do
    2.     '...
    3. Loop
    It's quite rare that you would actually want an infinite loop, but not unheard of. Sometimes the loop itself won't contain a condition for stopping but the body of the loop will, e.g.
    vb.net Code:
    1. If x > y Then Exit Do
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Click Here to Expand Forum to Full Width