So, hello guys today's topic is LOOP.lets talk about the loop=
A block of looping statements in C are executed for number of times until the condition becomes false.
'C' programming provides us
1) while = A "While" Loop is used to repeat a specific block of code an unknown number of times until a condition is met.
2) do-while = A do...while loop is similar to a while loop, except the fact that it is guaranteed to execute at least one time.
3) for loop =A while loop in C programming repeatedly executes a target statement as long as a given condition is true. Syntax.
*for loop example=
//example for loop
#include <stdio.h>
#include<conio.h>
void main()
{
int n, i;
printf("Enter an number which multiplication table u want: ");
scanf("%d", &n);
for (i = 1; i <= 10; ++i)
{
printf("%d * %d = %d \n", n, i, n * i);
}
}
*do while loop example=
// do while loop
#include<stdio.h>
#include<conio.h>
void main()
{
int a = 10;
do {
printf("value of a: %d\n", a);
a = a + 1;
}while( a < 20 );
}
*while loop example=
// Print numbers from 1 to 5
#include<stdio.h>
#include<conio.h>
void main()
{
int i = 1;
while (i <= 5)
{
printf("%d\n", i);
i++;
}
}
all these three type of loop i explained in my YouTube video,please watch it.=
Flowchart = for loop
No comments:
Post a Comment