
A while loop is a very simple loop type of loop. For loops allow you to easily iterate over a certain range of numbers, while loops iterate while a condition is true.
Having different kinds of loops in a program is really a matter of convenience rather than necessity. There really aren't any tasks that are not possible in either one, but there are some tasks that are much easier in one over the other.
Let's take a look at the anatomy of a while loop:
while(<condition>) { <code to run>}
No comments:
Post a Comment