QUESTION 1 \"What will be displayed when the following code is executed? $number
ID: 3884305 • Letter: Q
Question
QUESTION 1
"What will be displayed when the following code is executed?
$number = 6;
while($number > 0) {
$number -= 3;
echo $number;
}
3 0
6 3
6
3 0 -3
0 -3
QUESTION 2
If an if-statement or loop header has several statements associated with it you must enclose those statements in curly braces.
True
False
4 points
QUESTION 3
If two conditions are ORed together the result is false only if both conditions are false.
True
False
4 points
QUESTION 4
The following loop displays ______.
for($i=1; $i < 11; $i++)
echo $i;
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9
1 2 3 4 5
1 3 5 7 9
2 4 6 8 10
4 points
QUESTION 5
Assuming you don't use xor how do you test whether one and only one of two variables is zero?
if ($x == 0 and $y != 0 or $y == 0 and $x != 0)
if ($x = 0 or $y = 0)
if ($x == 0 or $y == 0)
if ($x == 0 and $y != 0 and $y == 0 and $x != 0)
QUESTION 6
Which city is echoed?
$answer = 4;
switch($answer) {
case 1:
echo ""Detroit"";
break;
case 3:
echo ""Chicago"";
break;
case 5:
echo ""Nashville"";
break;
default:
echo ""New York"";
}
New York
Chicago
Detroit
Nashville
QUESTION 7
What is the output for y?
$y = 0;
for($i=0; $i < 10; $i += 2) {
$y += $i;
}
echo $y;
20
10
11
9
QUESTION 8
With switch blocks if you don't include a break statement then execution continues within in the switch block until the next break statement or the end of the block.
True
False
QUESTION 9
if two conditions are ANDed together the result is true only if either condition is true.
True
False
QUESTION 10
true || false = false
True
False
QUESTION 11
How many times will the following code echo "Welcome to PHP"?
$count = 0;
while($count < 10) {
echo "Welcome to PHP";
$count += 1;
}
10
9
8
11
0
QUESTION 12
What is echoed for $y?
$y = 0;
for($i=1; $i < 10; $i++) {
$y += $i;
}
echo $y;
45
11
12
13
10
QUESTION 13
The break statement will cause a for-loop to skip to the next iteration.
True
False
QUESTION 14
A continue statement causes a loop to abort the current iteration and begin again with a new iteration.
True
False
QUESTION 15
What is the output?
$n1 = 31;
$n2 = 52;
$n3 = 10;
if ($n1 > $n2 && $n1 > $n3)
echo $n1;
elseif ($n2 > $n1 && $n2 > $n3)
echo $n2;
else
echo $n3;
52
10
0
31
QUESTION 16
Because there is only a single line associated with the if-statement in the following you don't need to enclose the echo statement in curly braces. But it is considered to be a good thing to do anyway.
if($x != 0)
echo "Not a zero.";
True
False
QUESTION 17
In a switch statement if none of the case labels match the tested variable or expression then the else clause is executed.
True
False
QUESTION 18
What is the output for $y?
$y = 0;
for($i=10; $i > 1; $i -= 2){
y$ += $i;
}
echo $y;
30
40
10
20
QUESTION 19
One pass through the body of a loop is called an iteration.
True
False
QUESTION 20
What is the output of the following code?
$x = 0;
while ($x < 4)
$x = $x + 1;
echo $x;
4
1
2
3
0
QUESTION 21
How many times is the echo statement executed?
for($i=0; $i < 10; $i++)
for($j=0; $j < 10; $j++)
echo "PHP"
100
20
10
45
QUESTION 22
With a switch statement the structure is set up to compare the variable value or expression in the parentheses of switch(expr) to a case label. If there is a match the code for that case is executed.
True
False
QUESTION 23
How many times will the following code echo ""Welcome to PHP""?
$count = 0;
while ($count < 10)
echo "Welcome to PHP";
an infinite number of times
9
10
11
8
QUESTION 24
What is $sum after this code runs?
$sum = 0;
for($d = 0; $d < 4; $d = $d + 0.5)
$sum += 1;
sum = 8
sum = 4
sum = 5
7
QUESTION 25
What value of $temp short circuits the $temp <= 100 test in this expression? if ($temp >= 32 and $temp <= 100)
$temp = 0
$temp = 32
$temp = 100
$temp = 75
3 0
6 3
6
3 0 -3
0 -3
Explanation / Answer
Q1 3 0
Q2 true
whenever there are multiple statement for the if loop they shoul be included in the parenthesis
Q3 true
or will return true if any one of the condition is true
Q4 1 2 3 4 5 6 7 8 9 10
since the loop will start from 0 and end at 10 since in the for loop it is written i < 11
as soon the value of the variable i is incremented to 11 the condition will be false and the for loop will not be executed firther
Q5 if ( ($x == 0 and $y != 0 ) or ($y == 0 and $x != 0) )
Q6 New York
Q7 20
since i is incremented by 2 and the resukts is added in y
so 2 + 4 + 6 + 8 = 20
Q8 true
Q9 false
for AND , if both the condition is true then only the result will be true otherwise the result will be false;
Q10 true
Q11 10 times
Q12 45
add 1 to 9
Q13 false
break statement will cause the for loop to terminatte the execute the next instruction after the for loop
Q14 true
Q15 52
Q16 true
Q17 false
if none of the case matches then the default in the switch is executed
Q18 30
add 10 + 8 + 6 + 4 + 2
Q19 true
Q20 4
Q21 100
it's a nested loop i loop will start from 0 to 9 i.e. 10 times for each value of i the j loop will execute from 0 to 9 i.e. 10 times so 10 * 10 = 100 times
Q22 true
Q23 infinite times
sice the condition in the while loop will always be true
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.