The while Loop

 

Overview

Computer programming cannot perform its assigned tasks without if logic statements (branching statements) and loops (repeated code). In the Visual Studio C# compiler there is one style of if statement and four loop sequences:

  • The for loop loops a prescribed number of times (unless a decision is made to jump out of the loop early).

  • The foreach loop is similar to the for loop except that the number of times the loop executes is set by some outside variable.

  • The while loop continues to loop until some test is met. This loop is used primarily to find a particular code sequence in a collection of arrays or files.

  • The do while loop makes the test for continuance at the bottom of the loop rather than at the top.

After the for loop discussion, the goto statement is briefly discussed as an alternative to the break statement. The switch case construct is shown at the end of the chapter.

 


Unlocking Microsoft C# V 2.0 Programming Secrets
Unlocking Microsoft C# V 2.0 Programming Secrets (Wordware Applications Library)
ISBN: 1556220979
EAN: 2147483647
Year: 2005
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net