While LOOP In C Programming

Posted on at


What Is a "Loop"?:
In programming often requires repeated execution of a sequence of operations.

A loop is a basic programming construct that allows repeated execution of a fragment of source code. Depending on the type of the loop, the code in it is repeated a fixed number of times or repeats until a given
condition is true.
Loops that never end are called infinite loops. Using an infinite loop is rarely needed except in cases where somewhere in the body of the loop a break operator is used to terminate its execution prematurely.

let’s look how to create a loop in the C# language.

While Loops

One of the simplest and most commonly used loops is while.

Syntax Of While Loop:

while (condition)                           

{
loop body;
}

Execution Of LOOP:

In the code above example, condition is any expression that returns a Boolean result – true or false. It determines how long the loop body will be repeated and is called the loop condition. In this example the loop body is the programming code executed at each iteration of the loop, i.e. whenever the input condition is true. The behavior of while loops can be represented by the following scheme:
In the while loop, first of all the Boolean expression is calculated and if it is
true the sequence of operations in the body of the loop is executed. Then
again the input condition is checked and if it is true again the body of the loop
is executed. All this is repeated again and again until at some point the
conditional expression returns value false. At this point the loop stops
and the program continues to the next line, immediately after the body of the
loop.
The body of the while loop may not be executed even once if in the beginning
the condition of the cycle returns false. If the condition of the cycle is never
broken the loop will be executed indefinitely.



About the author

shahryar-sultan

I'm a student.

Subscribe 0
160