+ 4

Is For loop is greater then other loops or not?

I am just confused as For loop is greater then other looks in working or just have equal preference to while and do while loops.

26th Feb 2018, 2:10 AM
Hassan Ali
Hassan Ali - avatar
4 Antworten
26th Feb 2018, 2:21 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 3
for in most languages is syntactic sugar for an equivalent while loop, which is in turn syntactic sugar for a set of labels and gotos down in assembly or IL. Given an efficient implementation of the language spec, these will be roughly equal. Some languages include internal "comments" giving hints to decompilers/reflectors about what the original code looked like, which will have a negligible effect on performance. I think you'll find that the biggest execution time differences between these are inherent in OS scheduling.
26th Feb 2018, 2:12 AM
Sudarshan Rai
Sudarshan Rai - avatar
+ 1
Most of us use for loop rather than while and do-while. We know that the basic requirements for any looping structure are, -Initialization -Condition -Incre/decrementation In for loop the above three are placed in a single line Whereas in while or do-while these statements are placed in different lines and at different places. Sometimes people forget to write any of the above three if the code is very long. In that case it is preferred to use for-loop
26th Feb 2018, 10:21 AM
Nashat - avatar
1st May 2018, 1:24 PM
Purusottam Lamichhane
Purusottam Lamichhane - avatar