main()
{
int i,n,t=0;
for(n=1;n<=100;++n)
{
for(i=1;i<=n;++i)
{
if(n%i==0)
++t;
}
if(t==2)
printf("\t%d",n);
t=0;
}
}
Loops in C are control flow
statements that facilitate the repeated execution of a block of code based on a
specified condition. C provides three primary types of loops: for loop, while
loop and do-while loop.
for loop
Simple for loop
Syntax
for(initial value; condition; increment/decrement)
{
statements;
}
The for statement followed three statements in the parenthesis separated by semi-colon (;).
Initialization of the variables to
execute once.
Conditional statement: It will check
the condition, if it is true then body part of the loop will be executed.
Increment/decrement statements: After
the condition check, increment/decrement statement is executed and once again
the condition is evaluated.
Ex.
output 1 2 3 4 5 6 7 8 9 10
Nested loop
Loop in loop is called nested loop
Syntax
for(initial value; condition; increment/decrement)
for(initial value; condition; increment/decrement)
statement;