}
cout << "value of a: " << a << endl;
a = a + 1;
}while( a < 20 );
return 0;
}
b)While
*/
return 0;
d)While True
#include <iostream>
using namespace std;
int main (int argc, char * const argv[]) {
int counter = 9;
while (true) {
cout << "Counter: " << counter << endl;;
counter--;
if (counter == 0) {
break;
}
}
return 0;
}
e) Do/ While
// do_while_statement.cpp
#include <stdio.h>
int main()
{
int i = 0;
do
{
printf_s("\n%d",i++);
} while (i < 3);
f) Jump / Loop
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout << "The loop with \'break\' produces
output as :\n" ;
for(int i = 1 ; i <= 10 ; i++)
{
if( (i%3) == 0 )
break ;
else
cout << i << endl ;
}
cout << "The loop with \'continue\' produce
output as : \n" ;
for(i = 1 ; i <= 10 ; i++)
{
if( (i%3) == 0 )
continue ;
else
cout << i << endl ;
}
g)If/ else
#include <iostream>
using namespace std;
int main ()
{
// local variable declaration:
int a = 100;
// check the boolean condition
if( a < 20 )
{
// if condition is true then print the following
cout << "a is less than 20;" << endl;
}
else
{
// if condition is false then print the following
cout << "a is not less than 20;" << endl;
}
cout << "value of a is : " << a << endl;
return 0;
}