12
Lecture#6 ي ن ا ي ف س ل ا.هدى ا ي قر ي و لط دى ا ا.ن ي ب ي ي لع م ا ي ا.ر ا ة ودي سع ل ا ة ي) ب ر لع ا كة ل م م لKingdom of Saudi Arabia ف4 ئلطا ا عة ام جTaif University ومات ل ع م ل ا ة ي نA ق ت و ات ي س حا ل ا ة ي كلCollege of Computer Science and IT وم ل ع م س ق ب س حا ل اComputer Science Department Programming 1

Lecture#6 ا. ريم العتيبي ا. ندى الطويرقي ا. هدى السفياني ا لمملكة العربية السعودية Kingdom of Saudi Arabia جامعة الطائف

Embed Size (px)

Citation preview

Page 1: Lecture#6 ا. ريم العتيبي ا. ندى الطويرقي ا. هدى السفياني ا لمملكة العربية السعودية Kingdom of Saudi Arabia جامعة الطائف

Lecture#6

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

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

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

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

Computer Science Department

  

  

Programming 1

Page 2: Lecture#6 ا. ريم العتيبي ا. ندى الطويرقي ا. هدى السفياني ا لمملكة العربية السعودية Kingdom of Saudi Arabia جامعة الطائف

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.

Page 3: Lecture#6 ا. ريم العتيبي ا. ندى الطويرقي ا. هدى السفياني ا لمملكة العربية السعودية Kingdom of Saudi Arabia جامعة الطائف
Page 4: Lecture#6 ا. ريم العتيبي ا. ندى الطويرقي ا. هدى السفياني ا لمملكة العربية السعودية Kingdom of Saudi Arabia جامعة الطائف

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.

Page 5: Lecture#6 ا. ريم العتيبي ا. ندى الطويرقي ا. هدى السفياني ا لمملكة العربية السعودية Kingdom of Saudi Arabia جامعة الطائف
Page 6: Lecture#6 ا. ريم العتيبي ا. ندى الطويرقي ا. هدى السفياني ا لمملكة العربية السعودية Kingdom of Saudi Arabia جامعة الطائف

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.

Page 7: Lecture#6 ا. ريم العتيبي ا. ندى الطويرقي ا. هدى السفياني ا لمملكة العربية السعودية Kingdom of Saudi Arabia جامعة الطائف

A general syntax of the switch statement

Page 8: Lecture#6 ا. ريم العتيبي ا. ندى الطويرقي ا. هدى السفياني ا لمملكة العربية السعودية Kingdom of Saudi Arabia جامعة الطائف
Page 9: Lecture#6 ا. ريم العتيبي ا. ندى الطويرقي ا. هدى السفياني ا لمملكة العربية السعودية Kingdom of Saudi Arabia جامعة الطائف
Page 10: Lecture#6 ا. ريم العتيبي ا. ندى الطويرقي ا. هدى السفياني ا لمملكة العربية السعودية Kingdom of Saudi Arabia جامعة الطائف

Break statement

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

Page 11: Lecture#6 ا. ريم العتيبي ا. ندى الطويرقي ا. هدى السفياني ا لمملكة العربية السعودية Kingdom of Saudi Arabia جامعة الطائف
Page 12: Lecture#6 ا. ريم العتيبي ا. ندى الطويرقي ا. هدى السفياني ا لمملكة العربية السعودية Kingdom of Saudi Arabia جامعة الطائف