NEW
Font size
WorksheetsWeb Application - PHP Repetition
Total questions: 15
Worksheet time: 10mins
Which of the following BEST describes a repetition control structure?
Executes statements only once.
Executes statements when the condition is false.
Executes statements more than once.
Executes statements randomly.
In a while loop, when is the loop body executed?
When the loop condition is false.
When the loop condition is true.
Before the loop condition is evaluated.
After the loop condition becomes false.
What will be the output of the following code?
HelloHelloHelloHello
HelloHelloHello
Hello Hello Hello
Hello Hello Hello Hello
In a for loop, what is the purpose of the initialization section?
To specify the condition for the loop to run.
To set the starting value of the loop.
To update the loop.
To define the statements to be executed.
Which of the following statements correctly defines the condition in a for loop?
The condition must be true for the loop to start.
The condition is checked after each iteration.
The condition is optional in a for loop.
The condition is checked only once.
What will be the output of the following code?
10 9 8 7 6 5
10 9 8 7 6
10 9 8 7
10 9 8
Given the code, what is the value of $x after the loop executes?
2
3
4
5
Which of the following is TRUE about a while loop?
It always runs at least once.
It may not run if the condition is false initially.
It runs indefinitely.
It does not require a condition.
In a loop, what will happen if the update step is omitted?
The loop will run indefinitely.
The loop will show an error.
The loop will not executes.
The loop will run once.
Which of the following is the correct syntax for a for loop in PHP?
for (condition; initialization; updating)
for (initialization; condition; updating)
for (initialization, condition, updating)
for (condition; initialization; updating);
How many loops are there in PHP?
1
2
3
4
Which of the following loop condition will print the word “Good” 50 times? Assume the starting value of the loop is 1.
($loop >= 50)
($loop <= 50)
($loop > 50)
($loop < 50)
For a loop for($i = 0; $i < 5; $i++), how many times will the loop execute?
0 times
4 times
5 times
6 times
What will happen to the following for loop?
It will result in a syntax error
The loop will execute indefinitely
The loop will not execute at all
PHP will throw a warning
Choose the CORRECT PHP code for Line 6 to generate output as shown below.
$x = $x * $x;
$x = $x + $x;
$x = $x * 2
$x = $x + 2
