Unlocking Microsoft C# V 2.0 Programming Secrets (Wordware Applications Library)

 

The do while Loop

The do while loop makes the test for continuance at the bottom of the loop, rather than at the top. It looks like this:

int intCharPointer = 0; Filename.length = 4; do { // Do something. intCharPointer++; // Increment the CharPointer. } while(intCharPointer < Filename.Length);

In this case, Filename is a string with four characters in it. Its char positions are numbered 0, 1, 2, and 3. The first time through the loop, char 0 is checked for something and intCharPointer is incremented to 1. The loop loops again and checks char 1; intCharPointer is incremented to 2. The loop loops again and checks char 2; intCharPointer is incremented to 3. The loop loops again and checks char 3; intCharPointer is incremented to 4, and the while test at the bottom fails.

 

Категории