0% found this document useful (0 votes)
34 views1 page

Statement

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views1 page

Statement

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Here, you will learn how to execute a statement or code block multiple times using

the for loop, structure of the for loop, nested for loops, and how to exit from the
for loop.

The for keyword indicates a loop in C#.


The for loop executes a block of statements repeatedly until the specified
condition returns false.

The for loop contains the following three optional sections, separated by a
semicolon:

Initializer: The initializer section is used to initialize a variable that will be


local to a for loop and cannot be accessed outside loop.
It can also be zero or more assignment statements, method call, increment, or
decrement expression e.g., ++i or i++, and await expression.

Condition: The condition is a boolean expression that will return either true or
false.
If an expression evaluates to true, then it will execute the loop again;
otherwise, the loop is exited.

Iterator: The iterator defines the incremental or decremental of the loop variable.

In the above example, int i = 0 is an initializer where we define an int variable i


and initialize it with 0.
The second section is the condition expression i < 10, if this condition returns
true then it will execute a code block.
After executing the code block, it will go to the third section, iterator.
The i++ is an incremental statement that increases the value of a loop variable i
by 1.
Now, it will check the conditional expression again and repeat the same thing until
conditional expression returns false.
The below figure illustrates the execution steps of the for loop.

The below figure illustrates the execution steps of the for loop.

You might also like