0

what is difference for loop to any other loop

all loop work in same

25th Aug 2016, 4:11 PM
ankit mishra
ankit mishra - avatar
4 Antworten
+ 3
Main Thing Is Their Syntax .. Next Thing Is For And While Are Entry Control Loops And Do While Is Exit Control Loop ...
25th Aug 2016, 4:31 PM
Shashank Pai
Shashank Pai - avatar
+ 1
Actually there is kind of deference every one of them work better in a certain situation better In case you know how many time the loop should be repeated , it is best to use the loop "for" For example to calculate the sum of ten number , to type nine value, so if you know how many time it the statements should be repeated it is the best to use the loop "for" ( of course you can easily use the loop "while" for the same situation); If you don't know how many time the loop should be repeated it the best to chose either "while" or " do ..while ", because in this situation there is a condition that specify when the loop should stop like ( if the user type zero stop the loop) or ( if the sum of typed numbers is greater than 100 stop the loop) so the main key is just to find the condition and the right order of the statement in those two loops There is only one deference between the "while" loop and the " do ...while " loop, the first check the condition before executing the statements for the first time, so if the condition is not verified in the first check , the program will just ignore the loop whiteout even execute it even once , the other one execute the statement one time than verify the condition to see if it should continue repeating the loop ( so the do while do loop guarantees that The loop will execute at least one time regardless of whither the condition is verified or not
25th Aug 2016, 11:24 PM
Raizel TheNoblesse
Raizel TheNoblesse - avatar
0
the biggest advantage of using for loop is that it initialize check condition and increment or decrement in a single line as compared to while and do while loop
25th Aug 2016, 4:43 PM
Aayush Rawat
Aayush Rawat - avatar
0
A for loop is like a while loop with the initialiser and post processing made obvious at the top, I much prefer to use them where possible unless it has no value counting the amount of runs/no temporary variables concerning the loop. Do whiles, while the logic is at the bottom, are nice if you want the block to always execute at least once, as Shashank said
25th Aug 2016, 8:09 PM
Ahkrin