Lecture#6 ا. ريم العتيبي ا. ندى الطويرقي ا. هدى السفياني ا...

Preview:

Citation preview

Lecture#6

ا.ريم العتيبي ا.ندى الطويرقي ا.هدى السفياني

السعودية ا العربية Kingdom ofلمملكةSaudi Arabia

الطائف TaifجامعةUniversity

المعلومات وتقنية الحاسبات College of Computer Science and ITكليةالحاسب علوم قسم

Computer Science Department

  

  

Programming 1

Compound (Block of) Statements

• The if and if. . .else structures control only one statement at a time.

• Suppose you want to execute more than one statement if the expression evaluates to true.

• To permit this, c++ provides compound statements.

Multiple Selections: Nested if

• Some problems require the implementation of more than two alternatives. You can include multiple selection in a program by using an if. . .else structure if the action statement itself is an if or if. . .else statement.

• When one control statement is located within another, it is said to be nested.

switch Structures• there are two selection structures in C++. The

first selection structure, which is implemented with if and if. . .else statements, usually requires the evaluation of a (logical) expression. The second selection structure, which does not require the evaluation of a logical expression, is called the switch structure. C++’s switch structure gives the computer the power to choose from among many alternatives.

A general syntax of the switch statement

Break statement

• To see the effect of break statements, we will delete it from previous program and recompile it.

Recommended