Chapter 5


1.

What are the parts to a for loop declaration?

 declare and initialize the loop counter set the conditions under which the loop will execute increment the loop counter

2.

What types of variables can be used for a switch statement?

integer or character

3.

What is the purpose of the default statement in a switch statement?

to handle situations other than the case statements you define. in short, to handle anything that does not fit one of your defined case statements.

4.

Why is it important to use the double equals sign in an if statement?

if you use a single equals, that is an assignment operator, and it will make your if statement always true, regardless of any user input.

5.

Why might a switch statement be better than an if statement in some cases?

if you have multiple selections (more than 2 or 3)

6.

What happens if you omit the break statements from your switch block?

then the next statement will also execute.

7.

What is the purpose of a for loop?

to execute a given code block a certain number of times

8.

Can you have an if statement without enclosing brackets?

yes, if there is only one line of code and it immediately follows the if statement.

9.

How do you implement more than one choice in an if statement?

with else statements

10.

What other possibilities besides equivalence can you use for if statements?

- = - =!= || &&

Answers

1.

• Declare and initialize the loop counter

• Set the conditions under which the loop will execute

• Increment the loop counter

2.

Integer or character

3.

To handle situations other than the case statements you define. In short, to handle anything that does not fit one of your defined case statements.

4.

If you use a single equals, that is an assignment operator, and it will make your if statement always true, regardless of any user input.

5.

If you have multiple selections (more than 2 or 3)

6.

Then the next statement will also execute.

7.

To execute a given code block a certain number of times

8.

Yes, if there is only one line of code and it immediately follows the if statement.

9.

With else statements

10.

<= >=!= || &&




C++ Programming Fundamentals
C++ Programming Fundamentals (Cyberrookies)
ISBN: 1584502371
EAN: 2147483647
Year: 2005
Pages: 197
Authors: Chuck Easttom

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