Infinite Loops


 

There are two standard ways that one can indicate to Java that you would like an infinite.

   while (true)
   {
      StatementList
   }

and

   for (;;)
   {
      StatementList
   }

In the second form we use a for statement with all three of the expressions that normally control the for loop left out. If we leave out the second expression (continuation condition), it is assumed to evaluate to true.

Since there are two possibilities, which one is better? Both of these have long histories dating back to the beginnings of the Java's predecessor language C. Some authors prefer one over the other. This author avoids the second possibility because it requires one to know something special about the semantics (meaning) of the missing condition. The first form does not require any special knowledge.

 

Back to the Exercise

Back to This Lab's Table of Contents


Back to the Table of Contents

Back to the Introduction


Copyright 2000 by Prentice Hall. All rights reserved.