Professional Documents
Culture Documents
format(item, format-specifier)
The While Loop
Make sure that the loop-continuation-condition eventually
becomes false so that the loop will terminate.
If your program takes an unusual long time to run and does
not stop, it may have an infinite loop.
Programmers often mistakenly execute a loop one time
more or less than intended. This kind of mistake is commonly
known as the off-by-one error.
Controlling a Loop with a Sentinel
Value
Another common technique for controlling a loop is
to designate a special input value, known as a
sentinel value, which signifies the end of the input.
A loop that uses a sentinel value in this way is called a
sentinel-controlled loop.
Don’t use floating-point values for equality checking
in a loop control.
The Break statement
Two keywords, break and continue, can be used in loop
statements to provide additional controls. Using break and
continue can simplify programming in some cases.
Overusing or improperly using them, however, can make
programs difficult to read and debug
Summary