When should we use for loop and when while in C ? In terms of speed up and memory consideration in embedded systems.
suvind
0
Newbie Poster
Recommended Answers
Jump to PostThey are identicdal in terms of speed and memory consumption. You can always substitute a while loop for a for loop, but not the other way around. The for loop is preferable when you know exactly how many loop iterations there will be. The while loop may be necessary when …
Jump to PostI agree with "Ancient Dragon": you generally use for loops when you know ahead of time exactly how many loops will be executed.
However, I would like to add another couple aspects you might want to consider.
1) If the body of the loop is small, and you …
All 5 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
DavidB
44
Junior Poster
Dervish1
37
Newbie Poster
isaacjames
0
Newbie Poster
Dervish1
37
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.