Looping statements, for loop , while loop , do while loop

Notes:

I. C# Looping or iterative Statements: [Starts at: 00min:00sec]
II. C# for loop : [Starts at: 05min:05sec]
III. C# while loop : [Starts at: 21min:22sec]
IV. C# do while loop : [Starts at: 27min:59sec]

I. C# Looping or iterative Statements: [Starts at:00min:00sec]
If we want to execute a statement or set of statements repeatedly then
we use looping or iterative statements.

Ex:
for loop (Entry control loop)
while loop (Entry control loop)
do while loop (Exit control loop)
for each loop (Entry control loop)

Example Code: Displaying "Hello Unity" 10 times

using UnityEngine;
public class LoopingStatements : MonoBehaviour {
void Start () {

Debug.Log ("Hello Unity");
Debug.Log ("Hello Unity");
Debug.Log ("Hello Unity");
Debug.Log ("Hello Unity");
Debug.Log ("Hello Unity");
Debug.Log ("Hello Unity");
Debug.Log ("Hello Unity");
Debug.Log ("Hello Unity");
Debug.Log ("Hello Unity");
Debug.Log ("Hello Unity");

}
}

II C# for loop : [Starts at: 05min:05sec]
for loop executes a statement or block of statements
as long as the expression evaluates to true

syntax:
for([initializers];[expression];[iterators])
{
statement(s);
}

Example Code: Displaying "Hello Unity" 10 times using for loop

using UnityEngine;
public class LoopingStatements : MonoBehaviour {
void Start () {

for (int counter = 1; counter <= 10; counter++) {
Debug.Log ("Hello Unity");
}

}
}

III. C# while loop : [Starts at: 21min:22sec]
while loop executes a statement or block of statements
as long as the expression evaluates to true

syntax:
while(expression)
{
statement(s);
}

Example Code: Displaying "Hello Unity" 10 times using while loop

using UnityEngine;
public class LoopingStatements : MonoBehaviour {
void Start () {

int counter = 1;
while (counter <= 10) {
Debug.Log ("Hello Unity");
counter++;
}

}
}

IV. C# do while loop : [Starts at: 27min:59sec]
do while loop executes a statement or block of statements
as long as the expression evaluates to true

syntax:
do
{
statement(s);
}while(expression);

Example Code: Displaying "Hello Unity" 10 times using do while loop

using UnityEngine;
public class LoopingStatements : MonoBehaviour {
void Start () {

int counter = 1;
do {
Debug.Log ("Hello Unity");
counter++;
} while (counter <= 10);

}
}

Note:
Use for loop when you know how many number of times loop will get execute
Use while loop when you dont know how many number of times loop will get execute
Use do while loop to execute a statement(s) at least once