C# Basic- Looping Statement
By Dhananjay Masal– CODEMIND Technology
Contact us +91 9890217463
1
Loops in C#:
- Loops are also called repeating statements or iterative
statements.
- also called Iteration Statements
- Looping in programming languages is a feature that facilitates
the execution of a set of instructions repeatedly while some
condition evaluates to true.
- The process of repeatedly executing a statement or group of
statements until the condition is satisfied is called looping
2
Loops
- Counter Loops are the loops, which execute a specific set
of instructions a certain number of times.
- Conditional Loops are the loops, which execute a specific
task until the condition is true.
3
Why do we need looping?
- The basic purpose of the loop is code repetition. So, whenever
the repetitions are required, then in place of writing the
statements, again and again, we need to go for looping.
- Types of Loops in C#
- For loop
- For Each Loop
- While loop
- Do while loop
4
While Loop in C# with Examples
A while loop is used for executing a statement repeatedly until a given condition returns false
while(condition) {
statements;
5
6
Do While Loop in C# with Examples
- do-while loop is a post-tested loop or exit-controlled loop i.e. first it will execute the loop
body and then it will be going to test the condition. That means we need to use the do-while
loop where we need to execute the loop body at least once.
- do {
- statements;
- }while(condition);
7
8
For Loop in C# with Examples
If we know the number of times, we want to execute some set of statements or instructions, then we should use
for loop. For loop is known as a Counter loop.
for(initialization; condition; increment/decrement){
//statements
9
10
Thank You
Success is not a milestone, it's a journey. And we have
vowed to help you in yours.
www.codemindtechnology.com
11