Loop control instructions

What are loops in C

●-●-●-●-●-●-●-●-●-●-●-●-●-●-●-●-●-●-●-●-●

here in this image you can see the symbol is repeating till it was said to stop in C we have three types of loops.

  • The while loop
  • The for loop
  • The Do-while-loop

The while loop

◊-◊-◊-◊-◊-◊-◊-◊-◊-◊-◊-◊-◊-◊-◊-◊-◊-◊-◊-◊

The while construct consists of a block of code and a condition/expression.[ The condition/expression is evaluated, and if the condition/expression is true, the code within all of their following in the block is executed. This repeats until the condition/expression becomes false. Because the while loop checks the condition/expression before the block is executed. Here is a flow chat of hoe the while loop works

See the source image

while syntax

◈-◈-◈-◈-◈-◈-◈-◈-◈-◈-◈-◈-◈-◈-◈-◈

The syntax of a while loop in C programming language is −

while(condition) 
{
statement(s);
}

Here, statement(s) may be a single statement or a block of statements. The condition may be any expression, and true is any nonzero value. The loop iterates while the condition is true.

When the condition becomes false, the program control passes to the line immediately following the loop.

remember don’t fall in a trap

♾♾♾♾♾♾♾♾♾♾♾♾♾♾♾♾♾♾♾♾♾♾♾♾♾

remember notes

The while loop will execute till the number you entered

ex

  1. A=1 ;

while ( A<=10)

{

statement one ;

statement two ;

}

2. if don increment it will be a infinite loop

more operators

;-):)^_^:-):-D^0^:D;-):)^_^:-):-D^0^:D;-):)^_^:-):-D^0^:D

there some operators we use in while ++variable variable ++ both of them are the most main they all increment by one ++variable increments and then assigns it to the variable variable++ does what the normal incrementation variable=variable+1 you can also use += -= /= *= for incrementation.

Leave a comment