For loop

 

Condition Looping:

àLoops are used to execute one or more statements multiple times until a specified condition is fulfilled.

àLoops can be nested in C#.

 

C# provides 4 loops that allow you to execute a block of code repeatedly until a certain condition is met; they are:

 

1.   for Loop.

2.   while loop.

3.   do while Loop.

4.   foreach Loop.

 

Each and every loop requires the following 3 things in common.

 

Initialization: that sets a starting point of the loop.

 

Condition: that sets an ending point of the loop.

 

Iteration: that provides each level, the iterator defines the incremental or decremental of the loop variable.


1. 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 syntax of the for loop is given below:

 

for ( initialization, condition, iteration )

{

 // These statements will be executed if the condition evaluates to true

}

 

Examples:

1.   Increment condition.

2.   Decrement condition.

3.   Multiple condition.

4.   Nested loop.

 

Real word:

You put your favourite song on a repeat mode. It is also a loop.

Comments

Popular posts from this blog

.NET Framework Introducton

CLR with advantages and architectures

Definition and features of C#.