Selection Control Structures, Schemes and Mind Maps of Programming Languages

Control Structures in C++ (switch Structure voiding Partially Understood Concepts and Techniques: Revisited switch Structures. : alternate to if-else.

Typology: Schemes and Mind Maps

2022/2023

Uploaded on 03/01/2023

arlie
arlie 🇺🇸

4.6

(18)

245 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Programming Language (630203)
Fall 2010/2011
Selection
Control Structures
Objectives of the Lecture
switch Structures
Avoiding Bugs by Avoiding Partially Understood Concepts and Techniques: Revisited
Example 1 & Example 2
switch structure
: alternate to if
switch
(integral) expression is evaluated first
Value of the expression determines which corresponding action is taken
Expression is sometimes called the
Programming Language (630203)
– Lecture Notes # 7
Control Structures
in C++ (switch
Structure
Avoiding Bugs by Avoiding Partially Understood Concepts and Techniques: Revisited
switch Structures
: alternate to if
-else
(integral) expression is evaluated first
Value of the expression determines which corresponding action is taken
Expression is sometimes called the
selector
Structure
)
Avoiding Bugs by Avoiding Partially Understood Concepts and Techniques: Revisited
pf3
pf4

Partial preview of the text

Download Selection Control Structures and more Schemes and Mind Maps Programming Languages in PDF only on Docsity!

Programming Language (630203)

Fall 2010/

Selection Control Structures

Objectives of the Lecture

 switch Structures

 Avoiding Bugs by Avoiding Partially Understood Concepts and Techniques: Revisited

 Example 1 & Example 2

 switch structure : alternate to if

 switch (integral) expression is evaluated first

 Value of the expression determines which corresponding action is taken

 Expression is sometimes called the

Programming Language (630203)

Fall 2010/2011 – Lecture Notes # 7

Control Structures in C++ (switch Structure

Avoiding Bugs by Avoiding Partially Understood Concepts and Techniques: Revisited

switch Structures

: alternate to if-else

(integral) expression is evaluated first

Value of the expression determines which corresponding action is taken

Expression is sometimes called the selector

Structure)

Avoiding Bugs by Avoiding Partially Understood Concepts and Techniques: Revisited

 One or more statements may follow a case label

 Braces are not needed to turn multiple statements i

 The break statement may or may

 switch, case, break, and default

Avoiding Bugs by Avoiding Partially Understood Concepts and Techniques:

 To output results correctly

The switch structure must include a

tements may follow a case label.

Braces are not needed to turn multiple statements into a single compound statement

statement may or may not appear after each statement.

default are reserved words

Avoiding Bugs by Avoiding Partially Understood Concepts and Techniques: Revisited

structure must include a break statement after each

nto a single compound statement.

Avoiding Bugs by Avoiding Partially Understood Concepts and Techniques:

statement after each cout statement

//Grade program with bugs.

 - Example 
  • #include //Line
  • using namespace std; //Line
  • int main() //Line
  • { //Line
    • int testScore; //Line
    • cout << "Enter the test score: "; //Line
    • cin >> testScore; //Line
    • cout << endl; //Line
    • switch (testScore / 10) //Line
    • { //Line
    • case 0: //Line
    • case 1: //Line
    • case 2: //Line
    • case 3: //Line
    • case 4: //Line
    • case 5: //Line - cout << "The grade is F." << endl; //Line
    • case 6: //Line - cout << "The grade is D." << endl; //Line
    • case 7: //Line - cout << "The grade is C." << endl; //LIne
    • case 8: //Line - cout << "The grade is B." << endl; //Line
    • case 9: //Line
    • case 10: //Line - cout << "The grade is A." << endl; //Line
    • default: //Line - cout << "Invalid test score." << endl; //Line
    • } //Line
    • return 0; //Line
  • } //Line