Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 13. Creating Conditional Stateme... > Checking for Conditions Using the Sw...

Checking for Conditions Using the Switch Statement

The switch statement also performs conditional logic. It takes up a bit more space as far as the number of lines it occupies, but switch statements are less verbose in their syntax and are easier to read when creating long lists of conditions.

The switch statement is a function call that is passed an expression, which is then used to check against different values in case comparisons. If a case clause resolves to true, code within the case statement is executed. The break statement at the end of each case breaks out of the switch statement if a case resolves to true. If a case clause resolves to false, the statement moves on to the next case statement in the switch block. If no case statements return true, a default clause can handle any resulting action, much like an else statement.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint