Which loop faster 'for' or 'while' | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Which loop faster 'for' or 'while'

15th Feb 2017, 7:31 AM
Abdulhameed Alhababi
Abdulhameed Alhababi - avatar
4 Answers
+ 13
You can utilise the <chrono> header to find out but I suppose the differences would only be a couple of nanoseconds.
15th Feb 2017, 12:05 PM
Hatsy Rei
Hatsy Rei - avatar
+ 4
It doesn't affect the performance whichever you use and even if it does it is so negligible you wouldn't even know.
15th Feb 2017, 7:40 AM
Varun Moghe
Varun Moghe - avatar
+ 1
it should be while since checking a single condition cab enter into the loop and execute. if the statement false, then ends the loop
15th Feb 2017, 6:30 PM
CH.P.V.S.Satish
+ 1
it should be while since by checking a single condition can enter into the loop and execute. if the statement false, then ends the loop
15th Feb 2017, 6:30 PM
CH.P.V.S.Satish