Skip over navigation

Basic Commands in C++

Problems

Other Basic Statements

How to Cite This SparkNote

Problem : How many test conditions can an if-statement check?

An if-statement checks only one test condition, although it can be a composite of many conditions logically chained together using the logical operators && and ||.

Problem : When should you use an else statement?

An else statement is used in an if statement when you want alternate code executed in the event that the test condition evaluates to false.

Problem : When are braces necessary for if/else-statements?

Braces are necessary whenever the body of the statement is more than one line long.

Problem : What does the default keyword in a switch-statement tell the program?

It tells the program what to do in the event that the switch-statement's test variable's value does not match any of the cases you specified.

Problem : When would you use a while-loop instead of a for-loop?

A while-loop is useful when you want to loop without initializing and incrementing a variable's value, as a for-loop allows you do.

Follow Us