#166 – Using the for Statement to Create an Infinite Loop
November 30, 2010 Leave a comment
You can create an infinite loop using either while or for.
In the example below, the body of the for loop will run forever.
// Run forever for (;;) { AskUserATriviaQuestion(); TellThemTheCorrectAnswer(); }
You can accomplish the same thing using while (true), but you might still use the for loop if you want to use a loop variable.
// Run forever for (uint questionNumber = 1; ; questionNumber++) { AskUserATriviaQuestion(questionNumber); TellThemTheCorrectAnswer(questionNumber); }