+ 33
Is this a wrong quiz?
One user challenged me and I came across this quiz: How many times will the following loop run? $i=5; while($i<10) { if($i%4==0) break; $i++; } The right answer is 3. Could you explain me why? I thought the answer would be 4. The condition of the loop was true 4 times. What do you think?
3 Respostas
+ 10
Report it.
The question was asked very badly.
Yes you are right the loop runs 4 times.
And 3 is the number of completed iterations.
The question should be something like "How often will the loop complete an iteration"
+ 5
Same here! I was vastly disappointed that such questions are _approved_! Quality of quizzes/challenges are dropped down after a lot of new questions were added. Some are nearly irrelevant to languages, some are bad worded, some are even wrong and some ... are nearly stupid IMHO. :-( Update: Just checked out a screenshot of that question that I made after I was shocked with answer. There is no author mentioned. If it means that such question are made by SL... It's horrifying.) 😥
If this loop will run 3 times than which one it will break from? :-)
+ 2
will run for 5,6,7 & 8, so are 4 times