- Introduction
- Control Structures
- If/Then Selection Structure
- If/Then/Else Selection Structure
- While Repetition Structure
- DoWhile/Loop Repetition Structure
- DoUntil/Loop Repetition Structure
- Do/LoopWhile Repetition Structure
- Do/LoopUntil Repetition Structure
- Assignment Operators
- For/Next Repetition Structure
- Example: Using the For/Next Structure to Compute Compound Interest
- SelectCase Multiple-Selection Structure
- Using the Exit Keyword in a Repetition Structure
- Logical Operators
- Introduction to Windows Application Programming
- Summary
3.6 DoWhile/Loop Repetition Structure
The DoWhile/Loop repetition structure behaves like the While repetition structure. As an example of a DoWhile/Loop structure, consider another version of the segment designed to find the first power of two larger than 1000:
Dim product As Integer = 2 Do While product <= 1000 product = product * 2 Loop
When the DoWhile/Loop structure is entered, the value of product is 2. The variable product is multiplied by 2 repeatedly, taking on the values 4, 8, 16, 32, 64, 128, 256, 512 and 1024 successively. When product becomes 1024, the condition in the DoWhile/Loop structure, product<=1000, becomes false. This condition causes the repetition to terminate, with 1024 as product's final value. Program execution continues with the next statement after the DoWhile/Loop structure.