Register|Login

Have a question? Click here to ask the community.

Quiz 17 – For Loop

| In: PHP Quizzes | 17,580 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. A for loop contains an initalizing expression, a condition statement expression, and an increment expression?

True
False

2. A for loop will check the condition statement before executing the segment of code between the curly braces?

True
False

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

<?php
   for ($counter = 20; $counter < 10; $counter++){
       echo "Hello Robert ";
   } 
   echo "Counter is: $counter";
?>

Hello Robert
Counter is: 20
Hello Robert Counter is: 22
Hello Robert Hello Robert Counter is: 22

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

<?php
   for ($counter = 15; $counter != 10; $counter--){
       echo "Hello ";
   } 
?>

Hello Hello
Hello Hello Hello
Hello Hello Hello Hello Hello
None of the above

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

<?php
   for ($counter = 10; $counter < 10; $counter = $counter + 5){
       echo "Hello";
   } 
?>

Hello Hello Hello Hello Hello
Hello Hello Hello
Hello
None of the above



4 Responses to Quiz 17 – For Loop

Avatar

ers3

April 28th, 2015 at 12:42 pm

Please explain the code for 3

Avatar

Robert Smith

April 28th, 2015 at 1:02 pm

What exactly are you having problems understanding with question number 3?

Avatar

ers3

April 29th, 2015 at 11:01 am

Thank you Robert. The question says that the for condition is not true; as the second element states 20 is less than 10. So I think the output be Counter is 20, is that correct?

Avatar

yancruz01

July 18th, 2015 at 7:30 pm

Fun quizzes, man.

Comment Form

You must be logged in to post a comment.

Users Online

Users Online: 6 Users

Most Users Ever Online: 91

Quiz Scores

Advertisments