【文章內(nèi)容簡介】
data series) ? The sentinel values must be selected so as not to conflict with legitimate data values A First Book of ANSI C, Fourth Edition 23 Sentinels (continued) A First Book of ANSI C, Fourth Edition 24 Sentinels (continued) ? One useful sentinel in C is the named constant EOF (End Of File) – The actual value of EOF is pilerdependent, but it is always assigned a code that is not used by any other character – EOF is defined in A First Book of ANSI C, Fourth Edition 25 Sentinels (continued) A First Book of ANSI C, Fourth Edition 26 Sentinels (continued) A First Book of ANSI C, Fourth Edition 27 The break and continue Statements ? A break forces an immediate exit from while, switch, for, and dowhile statements only while(count = 10) { printf(Enter a number: )。 scanf(%f, amp。num)。 if (num 76) { printf(You lose!)。 break。 /* break out of the loop */ } else printf(Keep on truckin!)。 } /* break jumps to here */ A First Book of ANSI C, Fourth Edition 28 The break and continue Statements (continued) ? The continue applies to loops only。 when a continue statement is encountered in a loop, the next iteration of the loop begins immediately while (count 30) { printf(Enter a grade: )。 scanf(%f, amp。grade)。 if(grade 0 || grade 100) continue。 total = total + grade。 count = count + 1。 } A First Book of ANSI C, Fourth Edition 29 The Null Statement ? A semicolon with nothing preceding it is also a valid statement, called the null statement 。 ? Use the null statement where a statement is syntactically required, but no action is needed ? Null statements typically are used either with while or for statements A First Book of ANSI C, Fourth Edition 30 The for Statement ? The for statement bines all four elements required to easily produce a loop on the same line for (initializing list。 tested expression。 altering list) statement。 ? This statement does not require that any of the items in parentheses be present or that they actually be used for initializing or altering the v