Understanding Iteration Statements
Learn about iteration statements in C#, including the looping with while, do, for, and foreach loops.
Iteration statements repeat a block of statements either while a condition is true (while and for statements) or for each item in a collection (foreach statement). The statement choice is based on a combination of ease of understanding to solve the logic problem and personal preference.
Looping with the while statement
The while statement evaluates a boolean expression and continues to loop while it is true. Let’s explore iteration statements:
Step 1: Use your preferred coding tool to add a new "Console App/console" project named IterationStatements to the Chapter03 workspace/solution.
In Visual Studio Code, select
IterationStatementsas the activeOmniSharpproject.
Step 2: In the Program.cs, delete the existing statements and then add statements to define a while statement that loops while an integer variable has a value less than 10, as shown in the ...