Syntax :
do
{
statement(s);
} while( condition );
Example :
#include <stdio.h>
int main ()
{
// declared local operand (variable)
int a = 1;
// do-while loop
do
{
printf("value of a: %d\n", a);
a = a + 1;
} while( a < 5 );
return 0;
}
Output :
value of a: 1 value of a: 2 value of a: 3 value of a: 4
One more Example where condition is false :
#include <stdio.h>
int main ()
{
// declared local operand (variable)
int a = 1;
//here, Condition is false. a is not equals to zero
do
{
printf("value of a: %d\n", a);
a = a + 1;
} while( a == 0 );
return 0;
}
Output :
value of a: 1
No comments:
Post a Comment