Is this a wrong quiz? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 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?

25th May 2017, 9:14 PM
Igor Makarsky
Igor Makarsky - avatar
3 Réponses
+ 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"
25th May 2017, 9:23 PM
Tim G
Tim G - avatar
+ 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? :-)
2nd Jun 2017, 6:19 PM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar
+ 2
will run for 5,6,7 & 8, so are 4 times
31st May 2017, 6:30 PM
Domingos Inacio Caetano
Domingos Inacio Caetano - avatar