Created
October 20, 2022 00:30
-
-
Save mshafae/746e191172af461f09f7b06bbebd3680 to your computer and use it in GitHub Desktop.
CPSC 120 Exampl of how to skip the first element of an array using a boolean flag.
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/746e191172af461f09f7b06bbebd3680 | |
#include <array> | |
#include <iostream> | |
#include <string> | |
int main(int argc, char const* argv[]) { | |
std::array<int, 6> my_array{10, 11, 12, 13, 14, 15}; | |
bool should_skip_first{true}; | |
for (const int& number : my_array) { | |
if (should_skip_first) { | |
// We should skip the first element and we are. | |
// Now set should_skip_first to false to signal that | |
// we are no longer skipping. | |
should_skip_first = false; | |
// Jump back to the top of the loop and continue. | |
continue; | |
} | |
std::cout << number << "\n"; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment