-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

C# 6 and .NET Core 1.0

Iteration statements repeat a block either while a condition is true
or for each item in a sequence. The choice of which statement to use is based on a combination of ease of understanding to solve the logic problem and personal preference.
Add a new Console Application project named Ch03_IterationStatements.
Set the solution's startup project to be the current selection.
The while
statement evaluates a Boolean expression and continues to loop while it is true
.
Type the following code inside the Main
method (remember to statically import the System.Console
type!):
int x = 0; while (x < 10) { WriteLine(x); x++; }
Press Ctrl + F5 and view the output in the console:
0 1 2 3 4 5 6 7 8 9
The do-while
statement is like while
except the Boolean expression is checked at the bottom of the block instead of the top, which means that it always executes at least once.
If you want to try the code for the do-while
statement, then select...
Change the font size
Change margin width
Change background colour