Repetition/looping control instruction



C4fun

Are you looking for the looping instructions ?

Then you should go for the loop statement , different looping instructions are available in c language , different syntax can be used to to get the desired results . Syntax varies with the kind of loop you used. 

The use of loop depands upon the the required place you want to use the loop for .

Like if you know the number of iterations to be executed then you should go for for loop .

If you don't know the number of iterations then you might go for while loop or do while loop . So ,in simple words it can be summarised in single word   

Here is the details of the topic to go with ,below is the explanation of each topic you would be requiring.


These instruction are used to repeat any statement n number of times depending on conditions

There are three ways
#for statement
#while statement
#do while statement



*for statement

Syntax
       ①                     ②            ③
for(initialization;condition;inc/dec)
{
Statement x;
}
  #order of execution
①②④③②④③②(false)⑤

·         Example
·         Print a 10 times
Int I;
for(i=1;i<=10;i++)
{
printf(“a”);
}
So to run the loop we are required one loop control variable like I in abaove example.


While statement

Syntax

while(condition)
{
True lock statement;
Inc/dec;
}
Statement x;



Since the condition is checked first in both for & while loop they are known as entry control loops.

Example
Int i=1;
while(i<=10)
{
printf(“a”);
I=i+1;
}




#do while statement

Syntax

do
{
True block statement;
Inc/dec;
}while(condition);
Statement x;








Comparison between while and do while loop
While
Do while

1.       It is entry control loop
1.       While is exit control loop
2.       Here the condition is checked first and if condition is true only then the block will be executed
2.       In do while block is executed first and then the condition is checked so block will execute at least 1 time
3.       In while if the condition is found true
4.       For n times the block wil execute n times.
3.       While in dowhile if the condition is true for n times the block will execute n+1 times.

5.       Ex
int i=1;
while(i<=10)
{
printf(“%d”,i);
I=i+1;
}
4.       Ex
int i=1;
do
{
printf((“%d”,i);
I=+1;
}
When you have gone through the syntax , now you need to brush up your knowledge by simple answering the different questions available in your mind .
Just try to solve them with the logic not by hit and trial method .



So what was the result you have got ?
All questions are answered ?
All correct?
If you have not answered any then don't think bad , about it it is your first time and you have played it well!!.

Share this program among your friends whom you think it would help them as when you build the simple program then you build and boost up your confidence so do share the blog among your friends and   remember sharing is caring so share as much as u can.


No comments

thanks for reading and sharing.I hope it would help you!!!!

Powered by Blogger.