Created
December 24, 2018 07:21
-
-
Save Bloofer/88fa15c9c2da2ac1f50d72a499c8364a to your computer and use it in GitHub Desktop.
block bracket example
This file contains 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
// Bad Idea | |
// this compiles and does what you want, but can lead to confusing | |
// errors if close attention is not paid. | |
for (int i = 0; i < 15; ++i) | |
std::cout << i << std::endl; | |
// Bad Idea | |
// the cout is not part of the loop in this case even though it appears to be | |
int sum = 0; | |
for (int i = 0; i < 15; ++i) | |
++sum; | |
std::cout << i << std::endl; | |
// Good Idea | |
// It's clear which statements are part of the loop (or if block, or whatever) | |
int sum = 0; | |
for (int i = 0; i < 15; ++i) { | |
++sum; | |
std::cout << i << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment