C++ language

Statement
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
Simple if statement:
 if (expression is true)
{
statement1;
}
statement2;
statement3;

 

if_else statement
 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";
Switch Statement:

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;
do while statement:

This is statement where first loop executed then condition evaluated.

 do
{
statement 1;
}
while (condition is true);
statement n ;
while statement:
#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 Statement:
 for(initial value; test condition; increment/decrement)
{ 
statement 1;
.
.
.
statement n;
}
Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: