Skip to content

Instantly share code, notes, and snippets.

@DocBohn
Created May 15, 2025 14:28
Show Gist options
  • Save DocBohn/ec42e6a6b091e3fa05debfcffd30b2c1 to your computer and use it in GitHub Desktop.
Save DocBohn/ec42e6a6b091e3fa05debfcffd30b2c1 to your computer and use it in GitHub Desktop.
Code demonstrating K&R's motivating example for `continue` doesn't need `continue`
void process_nonnegative_elements(int a[], int n) {
int i;
for (i = 0; i < n; i++) {
if (a[i] < 0) { /* skip negative elements */
continue;
}
// ... /* do positive elements */
}
}
void process_nonnegative_elements_without_continue(int a[], int n) {
int i;
for (i = 0; i < n; i++) {
if (a[i] >= 0) { /* skip negative elements */
// ... /* do positive elements */
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment