Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
This chapter is from the book

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.

  • + Share This
  • 🔖 Save To Your Account