• When one if statement contains another if statement then such type of structure is known as nested if.
  • Nested if structure also helps in multi-way decision making where one condition depends on other.
  • It has the following form:
if (condition 1)
{
   if (condition 2)      / * nested if */
   {
       Statement;
   }
   else
   {
       Statement;
   }
}
else
{
   Statement;
}

Example:

if (category==”sport”)
{
   if (gender==’m’)
   {
       mark=mark+bonus_mark;
   }
}
else
{
   mark=mark+5;
}

Leave a Reply

Your email address will not be published. Required fields are marked *