Infinite while Loop

We should be always careful while working with loops. It is because if we mistakenly set the test expression in such a way that it is never false, the while and do...while loop will run forever. This is called infinite while and do...while loop. For example,


\begin{lstlisting}
// Infinite while loop
while (true) {
// body of while loop
}
\end{lstlisting}

Let's take another example,


\begin{lstlisting}
// Infinite while loop
int i = 100;
while (i == 100) {
System.out.print(''Hey!'');
}
\end{lstlisting}

The infinite do...while loop works in a similar way as while loop.