Created
February 5, 2021 01:31
-
-
Save carlstoker/9648950ccf243da915f704565f88f231 to your computer and use it in GitHub Desktop.
While loop type comparisons
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
| #include <iostream> | |
| #include <string> | |
| using namespace std; | |
| int main () { | |
| //Good | |
| string input; | |
| do { | |
| cout << "Enter foo: "; | |
| cin >> input; | |
| } while (input.compare("foo")); | |
| //Okay | |
| cout << "Enter bar: "; | |
| cin >> input; | |
| while (input.compare("bar")) { | |
| cout << "Enter bar: "; | |
| cin >> input; | |
| } | |
| //Bad | |
| while (true) { | |
| cout << "Enter baz: "; | |
| cin >> input; | |
| if (!input.compare("bar")) { break; } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment