Lorem ipsum dolor sit amet, consectetur adipiscing elit. Test link
Posts

6.1 Conditional branching - if

1 min read
Image result for C++ if statementif statement

An if statement contains a Boolean expression and block of statements enclosed within braces.

Structure of if statement
if (boolean expression )
/* if expression is true */
statements... ; /* Execute statements */


If the Boolean expression is true then statement block is executed otherwise (if false) program directly goes to next statement without executing Statement block.

if...else statement
If statement block with else statement is known as as if...else statement. Else portion is non-compulsory.

Structure of if...else

if(condition)
{
&nbsp statements...
}
else
{
&nbsp statements...
}

If the condition is true, then compiler will execute the if block of statements, if false then else block of statements will be executed.

Nested if...else statement
We can use multiple if-else for one inside other this is called as Nested if-else.

Structure of Nested if...else

if(condition)
{
&nbsp statements...
}
else if
{
&nbsp statements...
}
else
{
&nbsp statements...
}

                      6.2 Conditional selection - switch          NEXT >>

You may like these posts

  • Exceptions provide a way to react to exceptional circumstances (like runtime errors) in our program by transferring control to special functions called handlers. C++ exception h…
  •   Encapsulation is the method of combining the data and functions inside a class. This hides the data from being accessed from outside a class directly, only through th…
  • A string is simply an array of characters which is terminated by a null character '\0' which shows the end of the string. Strings are always enclosed by double quotes. Whe…
  • A file is collection of related records, a record is composed of several fields and field is a group of character. This requires another standard C++ library called fstream which…
  • Object Oriented Programming has a special feature called data abstraction. Data abstraction allows ignoring the details of how a data type is represented. While defining a clas…
  • Constants refer to fixed values in the code that you can't change and they are called literals. Constants can be of any of the basic data types and can be divided into Integer l…

Post a Comment