Page 189 - CITS - Computer Software Application -TT
P. 189

COMPUTER SOFTWARE APPLICATION - CITS




           Warning: If you omit the break statement in a case that is not the last, and that case gets a match, the next case
           will also be executed even if the evaluation does not match the case!
           Example
           What happens if we remove the break statement from case “red”?


































           $favcolor is red, so the code block from case “red” is executed, but since it has no break statement, the code
           block from case “blue” will also be executed:
           The default Keyword































           The default keyword specifies the code to run if there is no case match:
           Example

           If no cases get a match, the default block is executed:




                                                           176

                             CITS : IT&ITES - Computer  Software Application - Lesson 47 - 62
   184   185   186   187   188   189   190   191   192   193   194