Control Flow

For Loop in C#

The for loop is a control structure that executes a block of code a specified number of times.


Syntax
for (initialization; booleanExpression; update) { 
   //statements 
}

Notes

initialization declares the initial value of the controling variable.

update is the change in the controling variable that occurs after each execution of the statements.

booleanExpression is the controling statement that must be true in order for the 'for' structure to loop and execute.

booleanExpression results in either a true or false output. It is created using comparing operators (==, >, =, <=, !=).

There can also be multiple boolean expressions within the parentheses (booleanExpression). The boolean expressions are connected through logical operators (&&, ||, !).


Example
for (int x = 0; x <10; x++) { 
   Console.WriteLine(x); 
} //x will continue to increment while it remains less than 10.

Add to Slack

< Switch Case   |   For Each >

© 2018 SyntaxDB. All Rights Reserved.