Today I learned about coding algorithm.
I learned about the functions for, while, and do while.
These are the looping functions for C.
for is used when there are pre-determined number of times, so it can loop through an array from start to finish but only for the specified number.
On the other hand, while is used when the loop carries on until a pre-determined outcome or scenario takes place. it may be instant, or even a thousand times. For example, you can loop until use press enter, and if there are no enter input, the loop will not stop.
do while, being similar in name, is actually really contrasting its brother while. while checks the statement before running the program, but do while actually runs the program before checking the statement. when the statement is true, it loops again.
there are many uses to these 3 loops, and each serves it's purpose well.
No comments:
Post a Comment