C# Tutorials - Herong's Tutorial Examples
∟Arrays and Loop Statements
∟"while" Loop Statements
This section describes 'while' loop statements. A 'while' loop statement is similar to a 'for loop statement.
A "for" loop is a "while" statement, which is identical to the "for" statement without
the initiation_statement and the iteration_statement. Here is the syntax of
a "while" statement:
while statement:
while (logical_expression) {
embedded_statements
)
When a "for" statement is encountered in an execution flow, it will follow the algorithm
bellow:
- Step 1: Evaluate the logical expression.
- Step 2: If the resulting value of the logical expression is true, run all the
embedded statements; otherwise, end this "while" statement.
- Step 3: After executing the embedded statements, if they are executed as part of
Step 2, loop back to Step 1.
Comparing the "while" statement with the "for" statement:
- The "while" statement is simpler. But the execution of the embedded statements
should affect the result of the logical expression. Otherwise, the logical
expression could be always resulted in true, and the loop becomes an endless
loop.
- The "for" statement offers a structure matches nicely with the array structure,
where the array index can initialized, checked against the length of the array,
then incremented by 1 at the end of each iteration.
Table of Contents
About This Book
Introduction of C# (C Sharp)
Data Type and Variables
Logical Expressions and Conditional Statements
►Arrays and Loop Statements
Creating and Using Arrays
Creating and Using Arrays - Example
"for" Loop Statements
►"while" Loop Statements
Data Type Features
Floating-Point Data Types
Passing Parameters to Methods
Execution Environment Class
Visual C# 2010 Express Edition
Class Features
C# Compiler and Intermediate Language
Compiling C# Source Code Files
MSBuild - Microsoft Build Engine
Memory Usages of Processes
Multithreading in C#
Async Feature from C# 5
System.IO.FileInfo Class
System.Diagnostics.FileVersionInfo Class
WPF - Windows Presentation Foundation
Partial Classes and Partial Methods
Archived Tutorials
References
Full Version in PDF/ePUB