Loops in C#

A loop is a block of statements that is repeated.
C# has three types of loops: while, for and do.
There is also a foreach that works with collections and arrays.

A loop has a Boolean expression to test.
If the expression is true the statements in the block are executed and then the test is performed again.
When the condition is false, the next statement after the loop is executed.
A while loop and a for loop test a Boolean expression at the beginning, a do loop tests the Boolean expression at the end.
While and for loops are executed zero or more times. Do loops are always executed at least once.

The Boolean expression is a check point:
The decision is made to execute the entire loop or not.
If the value of the Boolean expression changes during execution of the loop, the loop continues until the test is made again.
The loop does not end in the middle if the variable changes.

Each pass through the loop is called an iteration.

Please study the material at each of the links below.

  1. Microsoft Reference: for loops
  2. A Demo loop program
  3. For Loops
  4. Microsoft Reference: while loops
  5. While Loops
  6. While, cont.
  7. Endless loops
  8. Position of increment in loop
  9. Microsoft Reference: do loops
  10. do Loops
  11. Compare for, while, and do Loops
  12. Nested Loops
  13. For Each Loops
Like us on Facebook:

OER: Open Educational Resource
Creative Commons License Author: Janet E. Joy; Publisher: Zebra0.com
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
Creative Commons Attribution-NonCommercial 4.0 International License
Last modified: January 09 2018 08:20:25.