+ 35
[CLOSED] Is this a wrong PHP quiz?
Screenshot: http://dl4.joxi.net/drive/2018/02/20/0022/3274/1473738/38/e84eedf824.jpg How many times will the following loop run? $i=5; while ($i<10) { if($i%4==0) break; $i++; } The answer is 3. Why? The loop runs 4 times. But on the forth time it will be broken. So, what is this? Wrong question? Wrong answer? Maybe I am wrong? Please, explain. UPDATE: SoloLearn fixed this quiz.
6 odpowiedzi
+ 8
Depends on the definition of "run". The loop body is entered four times, yet it only completes three times. It's a bad question though and should be deleted or rephrased.
Sadly it is not the worst of the bunch. There is one "Choose One" PHP question floating around, where all answers provided are false.
+ 7
the answer must be 4 because run means start to execute, does not mean that iteration must be finished, if question be 'complete' then answer will be 3
+ 6
For me it is wrong answer, because loop will run 4th time but just not to the end.
+ 3
I would say this question is vague, They would have just asked the value of $i instead. The loop actually runs 4 times because it enters the loop body 4th time, checks if it is a multiple of 4 and breaks. Even though $i++ is skipped, it still considered an iteration.
+ 1
The answer's 4. Just like everybody said before me, the fourth time the loop's running, the condition is true and then clear the loop.
0
PHP is good language program for web services.but when the quiz gets wrong you have look after it to know what happens.