Loops??


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Loops??

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    Loops??

    [Originally posted by David]

    Can you have 2 loops within another loop?

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Loops??

    [Originally posted by xterra210]

    I dont think so? You'd think it would crash? You might be able tO:

    do while timer1.enabled = true
    do
    listbox1.additem"HI"
    loop
    loop


    but that could be simplified into

    do while timer1.enabled = true
    listbox1.additem "hi"
    loop



  3. #3
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Loops??

    [Originally posted by Emerson Racca]

    Why not? You can have many loops within an outer loop. Maybe I don't understand the question.

  4. #4
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Loops??

    [Originally posted by David Chapman]

    The short answer is yes.

    Nesting loops is fairly common in VB (and other languages).
    In fact nested loops are the backbone of many sort routines and are useful for filling multidimensional arrays.

    So long as you make sure that all of you loops exit (infinite loops are not fun) then you should have no problems with them.

    Dave

  5. #5
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Loops??

    [Originally posted by Chris Carta]

    As David said, YES. Also, as David said, don't let it loop endlessly. Make sure you address the exit of the loop. While 'Exit Do' or 'Exit For' work just fine, they are pretty close to a GOTO. (I DON'T like 'Goto's). I often use nested loops when looking up data for a one time query versus writing a stored procedure with a cursor in Oracle. Actually, I use them in many of my programs...which is why I write a program in the first place. If the program does not need nested loops it is probably something I could figure out at a glance.

    What is it that needs multiple loops? Maybe we can offer some coding examples.
    Chris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center