3 ms·
Okay, I was counting the nesting depth incorrectly. Here are a few more examples: § 3.8 Goto and labels found = 0; for (i = 0; i < n && !found; i++)
by susam 8y ago
Okay, I was counting the nesting depth incorrectly. Here are a few more examples:
§ 3.8 Goto and labels
found = 0;
for (i = 0; i < n && !found; i++)
for (j = 0; j < m && !found; j++)
if (a[i] == b[j])
found = 1;
if (found)
/* got one: a[i-1] == b[j-1] */
...
else
/* didn't find any common element */
§ 6.3 Arrays of Structures
/* count C keywords */
main()
{
int n;
char word[MAXWORD];
while (getword(word, MAXWORD) != EOF)
if (isalpha(word[0]))
if ((n = binsearch(word, keytab, NKEYS)) >= 0)
keytab[n].count++;
for (n = 0; n < NKEYS; n++)
if (keytab[n].count > 0)
printf("%4d %s\n",
keytab[n].count, keytab[n].word);
return 0;
}
- tom_mellior 8y agoThanks. I still find these a bit more palatable than your loop-in-an-else-in-a-loop (there are no elses and no loops inside ifs here), but yeah, I can imagine that K&R might have written it the same way as you did.