Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
196 Part II: Controlling Program Execution 2. 3. 4. the text "empty" in the active cell. When Visual Basic encounters the first non-empty cell, it exits the loop. Open a new workbook and enter a value in any cell within the specified range -- A1:H10. Choose Developer | Macros. In the Macro dialog, select the EarlyExit procedure and click Run. Nested Loops So far in this chapter you have tried out various loops. Each procedure dem- onstrated the use of each individual looping structure. In programming practice, however, one loop is often placed inside another. Visual Basic allows you to "nest" various types of loops (For and Do loops) within the same pro- cedure. 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 a specific task more effectively. The following ColorLoop procedure illustrates how one For...Next loop is nested within another For...Next loop.