![]() In the first example, we can prove that the loop terminates when n is positive.īut in general, it is not so easy to tell whether a loop terminates. This example will print the number 3 forever, or at least until you terminate the program.Īn endless source of amusement for computer scientists is the observation that the directions on shampoo, “Lather, rinse, repeat,” are an infinite loop. Otherwise, the loop will repeat forever, which is called an infinite loop: int n = 3 Simple for Loop A for loop is a control structure that allows us to repeat certain operations by incrementing and evaluating a loop counter. ![]() The body of the loop should change the value of one or more variables so that, eventually, the condition becomes false and the loop terminates. Overview In this article, well look at a core aspect of the Java language executing a statement or a group of statements repeatedly using a for loop. ![]() This type of flow is called a loop, because the last step “loops back around” to the first.įigure 6.1 shows this idea using a flowchart.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |