What do you mean by looping statement how many type of loops?

What do you mean by looping statement how many type of loops?
What do you mean by looping statement how many types of loops?

What do you mean by looping statement how many types of loops?

Loop: To run the body statement continuously until The required condition is fulfilled is called looping.

 It is used to perform looping operations when the condition is false the execution of the loop will be terminated.

Some Others Languages Loops

👉C++ Loops 

👉Java Loops

👉Python Loops


While loop: While loop when program execution starts before condition check then statement execution.while loop is the most useful loop.it is called the while loop.

Syntax of while loop


while(condition)

{

//statement

Increment/decrement

}


How To while loop in C?

#include <stdio.h>

int main()

{

int a=1;

while(a<=10)

{

printf("%d ",a);

a++;

} 

}

*****OUTPUT*****

1 2 3 4 5 6 7 8 9 10


How To Use while loop user input in C?

#include <stdio.h>

int main()

{

int i=1,n;

printf("Enter any number:");

scanf("%d",&n);

while(i<=10)

{

printf("%d ",n*i);

i++;

} 

}

*****OUTPUT*****

Enter any number:4

4 8 12 16 20 24 28 32 36 40


Do-while loop: A do-while loop is similar to the while loop with one important difference. the do-while loop is executed at least one time. do-while loop if the test expression is true the body of the loop is executed again and test expression is evaluated.

Syntax of do-while loop

do

{

//statement

while(condition);

}


How to do-while loop in C? 

#include <stdio.h>

int main()

{

int i=1;

do

{

printf("%d ",i);

i++;

}

while(i<=10);

}

*****OUTPUT*****

1 2 3 4 5 6 7 8 9 10


How To do-while loop user input in C? 

#include <stdio.h>

int main()

{

int i=1,n;

printf("Enter any number:");

scanf("%d",&n);

do

{ 

{

printf("%d ",n*i);

i++;

}

}

while(i<=10);

}

*****OUTPUT*****

Enter any number:5

5 10 15 20 25 30 35 40 45 50


For Loop: A for loop in three-part initialization, condition, and increment/decrement. 

An initialization part is executed only one time and then a condition check.

for loop is very easy to understand loop because three-parts only one line. it is called the for a loop.

Syntax of for loop


for(initialization;condition;increment/decrement)

for(int i=1;i<=10;i++)

{

//Statement;

}


How to Use for loop in C?

#include <stdio.h>

int main()

{

for(int i=1;i<=10;i++)

{

printf("%d\n",i);

}

}

*****OUTPUT****

1 2 3 4 5 6 7 8 9 10


How To Use for loop user input in C?

#include <stdio.h>

int main()

{

int n;

printf("Enter any number:");

scanf("%d",&n);

for(int i=1;i<=10;i++)

{

printf("%d",i*n);

}

}

*****OUTPUT*****

Enter any number:7

7 14 21 28 35 42 49 56 63 70

 
Nested Loop: A nested loop inside another loop is called the nested loop.

Syntax of Nested loop


for(initialization;condition;increment/decrement)

{

for(initialization;condition;increment/decrement)

{

Statement

}

Statement

}


How To Use Nested loop in C?

#include <stdio.h>

int main()

{

for(int i=1;i<=10;i++)

{

printf("number:%d\n",i);

}

}

*****OUTPUT*****

1 2 3 4 5 6 7 8 9 10


How To Use Nested Loop user input in C?

#include <stdio.h>

int main()

{

int n,x,num;

printf("Enter any number:");

scanf("%d",&num);

for(int i=1;i<=num;i++)

{

n=i,x=0;

for(int j=2;j<=n-1;j++)

{

if(n%j==0)

{

x=1

}

}

 if(x==0)

printf("%d ",n);

}

}


*****OUTPUT*****

Enter any number:25

1 2 3 5 7 11 13 17 19 23


Tags

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.