Chapter Summary

I l @ ve RuBoard

Chapter Summary

The if statement uses a test condition to control whether a program executes the single simple statement or block following the test condition. Execution occurs if the test expression has a nonzero value and doesn't occur if the value is zero. The if else statement enables you to select from two alternatives. If the test condition is nonzero, the statement before the else is executed. If the test expression evaluates to zero, the statement following the else is executed. By using another if statement to immediately follow the else , you can set up a structure that chooses between a series of alternatives.

The test condition is often a relational expression , that is, an expression formed by using one of the relational operators discussed in Chapter 6, "C Control Statements: Looping." By using C's logical operators, you can combine relational expressions. For example, you can test to see if x is greater than 0 and less than 20.

The conditional operator ( operand1 ? operand2 : operand3 ) creates an expression whose value is governed by its first operand and is given by one of the next two operands. If the first operand is nonzero, the whole expression has the value of operand2 ; otherwise , the value that of operand3 .

The ctype .h family of character functions, such as isspace () and isalpha () , offers convenient tools for creating test expressions based on classifying characters .

The switch statement enables you to select from a series of statements labeled with integer values. If the integer value of the test condition following the switch keyword matches a label, execution goes to the statement bearing that label. Execution then proceeds through the statements following the labeled statement unless you use a break statement.

The break , continue , and goto are jump statements that cause program flow to jump to another location in a program. A break statement causes the program to jump to the next statement following the end of the loop or switch containing the break . The continue statement causes the program to skip the rest of the containing loop and to start the next cycle.

The control statements presented in these last two chapters will enable you to tackle programs much more powerful and ambitious than those you worked with before. As proof, just compare some of the examples in these chapters to those of the earlier chapters.

I l @ ve RuBoard


C++ Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 314
Authors: Stephen Prata

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net