5.5. While Repetition Statement

A repetition statement (also called a looping statement or a loop) allows you to specify that an action should be repeated, depending on the value of a condition (called the loop-continuation condition).

As an example of a While statement (sometimes more formally referred to as the While...End While statement), consider a program designed to find the first power of 3 larger than 100 (Fig. 5.4). In line 5, we take advantage of a Visual Basic feature that allows variable initialization to be incorporated into a declaration. When the While statement is entered (line 9), product is 3. Variable product is repeatedly multiplied by 3 (line 11), taking on the values 3, 9, 27, 81 and 243, successively. When product becomes ...

Get Visual Basic 2005 for Programmers: Deitel Developer Series, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.