If-Else V.S. Switch end of flow

Posted by Chris Okyen on Programmers See other posts from Programmers or by Chris Okyen
Published on 2012-09-21T21:45:20Z Indexed on 2012/09/21 21:55 UTC
Read the original article Hit count: 315

Filed under:
|

I was wondering the if if-else statements, is like a switch statement that does not have a break statement.To clarify with an example, will the if-else statement go through all the boolean expressions even if comes to one that is true before the final one... I.E., if boolean_expression_1 was true, would it check if boolean_expression_2 is true? If not, why do switch statements need break statements but if-else statements do not? And if they do, I ask the opposite sort question proposed in the previous sentence.

if( boolean_expression_1 )
  statement_1
else if( boolean_expression_2 )
  statement_2
else 
  default_statement

switch( controlling_expression )
{
case: ( A )
....
case: ( z )
}

© Programmers or respective owner

Related posts about java

Related posts about switch-statement