Wednesday, January 04, 2012

if-else Statement

Till now we have learnt, the statement(s) is/are executed when the condition with in if statement is true, but we can also execute statement(s) when the condition is false. To execute the statement(s), when the condition becomes false, we need to use else statement along with if statement.

Syntax for if-else statement:



if (condition=true)
{
  Statement 1;
  Statement 2;
  ------------
  Statement n;
}

else

{
  Statement 1;
  Statement 2;
  ------------
  Statement n;
}


The statements with in the braces after the else statement are performed when the condition=false.

No comments:

Post a Comment

Please give your valuable comments or queries if you fell its helpful or if you like the contents of the site. Thanks...