Register|Login

Have a question? Click here to ask the community.

Quiz 14 – Switch Statements

| In: PHP Quizzes | 17,504 views

*You are currently not logged in and your quiz score will not be recorded. Please login or register if you would like to submit your quiz score.

Directions: Answer all questions. Any questions skipped will be scored as wrong answers. Good Luck! :)

1. Which of the following cases is a correct way to write a case for a switch statement?

case “Mark”;
case “Mark”::
case “Mark”:
case “Mark”{

2. The default case is executed if all the other cases for a switch statement evaulate to false?

True
False

3. What will be displayed in a browser when the following PHP code is executed:

<?php
   $variable = 2;
   switch ($variable) {
       case 1:
           echo "Hello World";
           break;
       default:
           echo "Hello Robert";
           break;
   }
?>

Hello World
Hello Robert
Nothing Will Be Displayed

4. What will be displayed in a browser when the following PHP code is executed:

<?php
   $variable = 1;
   switch ($variable) {
       case 1:
           echo "Hello World";
       default:
           echo "Hello Robert";
           break;
   }
?>

Hello World
Hello Robert
Hello WorldHello Robert
Nothing Will Be Displayed

5. What is missing from case 2 in the switch statement below:

<?php
   $variable = 1;
   switch ($variable) {
       case 1:
           echo "Hello World";
           break;
       case 2:
           echo "Hello Tom";
       default:
           echo "Hello Robert";
           break;
   }
?>

break:
break()
break;
None of the above

Comment Form

You must be logged in to post a comment.

Users Online

Users Online: 4 Users

Most Users Ever Online: 91

Quiz Scores

Advertisments