| < Day Day Up > |
|
What characters are used to begin and end compound statements?
opening and closing braces { ... }
2.How does the if-else statement differ from the if statement?
The if...else statement offers an alternative course of action in the event the expression evaluates to false.
What control statement can be used in place of nested if-else statements?
switch
Why should a break statement be added to the end of each case of a switch statement?
To prevent execution falling through to the next case statement.
What is the purpose of a default case in a switch statement?
To provide a default course of action should no previous case apply.
What is the difference between a while and a do-while statement? When would you use a do-while instead of a while statement?
A do...while executes the body at least once regardless of the value of the expression. Use a do...while when your have to execute the body of the statement at least once.
Convert the following while statement to a for statement:
int i = 0; while(i<10){ //do something i++; }
for(int i=0; i<10; i++){
//do something
}
What will happen when the following code executes:
int i = 0; while(i++ < 3){ cout<<"i = "<<i<<endl; break; }
The value of i is incremented to 1 and the string i = 1 is printed to the screen, then the break causes the while loop to terminate.
What happens when the following code executes:
int i = 0; while(i < 3){ cout<<"i = "<<i<<endl; continue; i++; }
The string i = 0 is repeatedly printed to the screen. The continue forces the while loop to repeat forever because i is never allowed to increment.
True/False: Goto statements can be used to jump outside of functions.
FALSE
| < Day Day Up > |
|