Thursday, 22 March 2012

Problem: When have we use IF STATEMENT and when have we use SWITCH STATEMENT?
Solution:

·         If statement: executes a set of commands if the condition is true.
  if ( condition ) { statement; }
 else if ( condition ) { statement; }
  else { statement; }
·        
·         Switch statement: allows a program to evaluate an expression and attempt to match it to a case label.
  Switch ( expression )
  {   Case label1: Statements; Break;
        Case label2: Statements; Break;
        Default:       Statements;  Break; }

No comments:

Post a Comment