| Previous | Home | Next |
if Statement
In if statement condition evaluated if condition is true then statement with in >if block will be executed otherwise control go to else block will executed.
- Simple if statement
- if_else statement
if (expression is true)
{
statement1;
}
statement2;
statement3;
if (expression is true)
{
statement1;
}
else
{
statement2;
}
statement3;
if (x == 203035) // if statement
cout << "x is 203035";
else //else statement
cout << "x is not 203035";
This is a multi branching Statement which is based on condition. Control is transfer to one of the many statements.
switch (expression)
{
case 1:
{
statement 1:
.
.
.
statement n;
}
case 2:
{
statement 1:
.
.
.
statement n;
}
.
.
.
.
default:
{
statement 1:
.
.
.
statement n;
}
}
statement;
This is statement where first loop executed then condition evaluated.
do
{
statement 1;
}
while (condition is true);
statement n ;
#include <iostream>
using namespace std;
int main ()
{
int number;
cout << "Enter the initial > ";
cin >> n;
while (n<10) {
cout << n << ", ";
++n;
}
cout << "OUT!\n";
return 0;
Enter the initial>1
1,2,3,4,5,6,7,8,9,10,OUT!
for(initial value; test condition; increment/decrement)
{
statement 1;
.
.
.
statement n;
}
| Previous | Home | Next |