+ 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.

20th Feb 2018, 11:34 PM
Igor Makarsky
Igor Makarsky - avatar
6 Answers
+ 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.
20th Feb 2018, 10:57 AM
Tob
Tob - avatar
+ 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
20th Feb 2018, 1:35 PM
Vukan
Vukan - avatar
+ 6
For me it is wrong answer, because loop will run 4th time but just not to the end.
20th Feb 2018, 10:48 AM
ThreeG
ThreeG - avatar
+ 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.
20th Feb 2018, 2:51 PM
Ravi Chandra Enaganti
Ravi Chandra Enaganti - avatar
+ 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.
21st Feb 2018, 10:54 PM
Apple
0
PHP is good language program for web services.but when the quiz gets wrong you have look after it to know what happens.
21st Feb 2018, 3:07 AM
Paladugu Darwin Chowdary
Paladugu Darwin Chowdary - avatar