Nested Loops

So far in this chapter you have tried out various loops. Each procedure demonstrated the use of each individual looping structure. In programming practice, however, one loop is often placed inside of another. Visual Basic allows you to "nest" various types of loops (For and Do loops) within the same procedure. When writing nested loops, you must make sure that each inner loop is completely contained inside the outer loop. Also, each loop has to have a unique counter variable. When you use nesting loops, you can often execute the specific task more effectively.

Part I

The GetFormsAndControls procedure shown in the following hands-on illustrates how one For Each.. .Next loop is nested within another For Each...Next loop.

0 0

Post a comment