Skip to content

Instantly share code, notes, and snippets.

@Bloofer
Created December 24, 2018 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bloofer/88fa15c9c2da2ac1f50d72a499c8364a to your computer and use it in GitHub Desktop.
Save Bloofer/88fa15c9c2da2ac1f50d72a499c8364a to your computer and use it in GitHub Desktop.
block bracket example
// 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