![]() |
![]() |
![]() |
C++ Reference: For and While Loops
for
Video Tutorials
Example 1
// Loop 10 times with the index running from 0 to 9 for (unsigned int uiIndex = 0; uiIndex < 10; ++uiIndex) { // Some code }
Example 2
// Infinite loop for (;;) { // Some code }
Example 3
// Equivalent to a while loop for (;!bDone;) { // Some code which eventually changes the value of 'bDone' }
Example 4
// For loop with multiple initializers and updates for (int i = 0, int j = 5; i < 10; ++i, ++j) { // Some code }
while
Video Tutorials
Lesson 8: While and Do While Loops
Example 1
// Runs as long as done is false while (!bDone) { // Some code which eventually changes the value of 'bDone' }
Example 2
// Similar to a for loop int iIndex = 0; while (iIndex < 10) { // Some code ++iIndex; }
Example 3
// Infinite loop while (true) { // Some code }
do while
Video Tutorials
Lesson 8: While and Do While Loops
Example 1
// Loop until 'bDone' is true, runs at least once do { // Some code which eventually changes the value of 'bDone' } while (!bDone);
Example 2
// Infinite loop do { // Some code which eventually changes the value of 'bDone' } while (true);
![]() |
![]() |
![]() |
| Home | | | Reference | | | Play Games! | | | Blog | | | Forum | | | Site Map | | | Contact Us |





