Created
October 4, 2022 03:34
-
-
Save mshafae/268280c9d47f4388b5a74ad22b735cd2 to your computer and use it in GitHub Desktop.
Counting to 5 with three different loops.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Gist https://gist.github.com/268280c9d47f4388b5a74ad22b735cd2 | |
#include <iostream> | |
const int kMax = 5; | |
int main(int argc, char const *argv[]) { | |
std::cout << "Counting to " << kMax << " with a for loop.\n"; | |
for (int counter = 0; counter < kMax; counter++) { | |
std::cout << counter << "\n"; | |
} | |
std::cout << "Counting to " << kMax << " with a while loop.\n"; | |
int while_counter = 0; | |
while (while_counter < kMax) { | |
std::cout << while_counter << "\n"; | |
while_counter++; | |
} | |
std::cout << "Counting to " << kMax << " with a do-while loop.\n"; | |
int do_counter = 0; | |
do { | |
std::cout << do_counter << "\n"; | |
do_counter++; | |
} while (do_counter < kMax); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment