SlideShare a Scribd company logo
1 of 35
CONTROL STRUCTURES (SELECTION)
Objectives
In this chapter, you will:
• Learn about control structures
• Examine relational and logical operators
• Explore how to form and evaluate logical
  (Boolean) expressions
• Discover how to use the selection control
  structures if, if...else, and switch in a
  program
                                              2
Control Structures
• A computer can proceed:
  – In sequence
  – Selectively (branch) - making a choice
  – Repetitively (iteratively) - looping
• Some statements are executed only if certain
  conditions are met
• A condition is met if it evaluates to true


                                                 3
Control Structures (cont.)




                             4
Relational Operators
• A condition is represented by a logical
  (Boolean) expression that can be true or
  false
• Relational operators:
  – Allow comparisons
  – Require two operands (binary)
  – Evaluate to true or false



                                             5
Relational Operators (cont.)




                               6
Relational Operators (cont.)
• You can use the relational operators with all
  three simple data types:
  – 8 < 15 evaluates to true
  – 6 != 6 evaluates to false
  – 2.5 > 5.8 evaluates to false
  – 5.9 <= 7.5 evaluates to true




                                                  7
Relational Operators (cont.)




                               8
Logical (Boolean) Operators and
          Logical Expressions
• Logical (Boolean) operators enable you to
  combine logical expressions


           unary

           binary

           binary




                                              9
Logical (Boolean) Operators and
   Logical Expressions (cont.)




                                  10
11
12
Order of Precedence

• Relational and logical operators are
  evaluated from left to right
• The associativity is left to right
• Parentheses can override precedence




                                         13
Order of Precedence (cont.)




                              14
Order of Precedence (cont.)




                              15
Order of Precedence (cont.)




                              16
Order of Precedence (cont.)




                              17
Selection: if and if...else
•   One-Way Selection
•   Two-Way Selection
•   Compound (Block of) Statements
•   Multiple Selections: Nested if
•   Comparing if...else Statements with a
    Series of if Statements



                                            18
Selection: if and if...else (cont.)
• The syntax of one-way selection is:



• The statement is executed if the value of the
  expression is true
• The statement is bypassed if the value is false;
  program goes to the next statement
• if is a reserved word

                                                     19
One-Way Selection (cont.)




                            20
Two-Way Selection
• Two-way selection takes the form:




• If expression is true, statement1 is executed;
  otherwise, statement2 is executed
   – statement1 and statement2 are any C++ statements
• else is a reserved word


                                                    21
Two-Way Selection (cont.)




                            22
Two-Way Selection (cont.)




                            23
Compound (Block of) Statement
• Compound statement (block of statements):




• A compound statement is a single statement

                                               24
Compound (Block of) Statement
(cont.)
 if (age >   18)
 {
   cout <<   "Eligible to vote." << endl;
   cout <<   "No longer a minor." <<
   endl;
 }
 else
 {
   cout <<   "Not eligible to vote." <<
   endl;
   cout <<   "Still a minor." << endl;
 }
                                            25
Multiple Selections: Nested if
• Nesting: one control statement in another
• An else is associated with the most recent if that
  has not been paired with an else




                                                       26
27
Comparing if…else Statements with
     a Series of if Statements




                                28
Confusion Between == and =
• C++ allows you to use any expression that can
  be evaluated to either true or false as an
  expression in the if statement:
  if (x = 5)
      cout << "The value is five." << endl;
• The appearance of = in place of == resembles
  a silent killer
  – It is not a syntax error
  – It is a logical error

                                                 29
switch Structures
• switch structure: alternate
  to if-else
• switch (integral) expression
  is evaluated first
• Value of the expression
  determines which
  corresponding action is taken
• Expression is sometimes
  called the selector


                                  30
31
switch Structures (cont.)
• One or more statements may follow a case
  label
• Braces are not needed to turn multiple
  statements into a single compound statement
• The break statement may or may not appear
  after each statement
• switch, case, break, and default are
  reserved words


                                            32
33
Summary
• Control structures alter normal control flow
• Most common control structures are selection and
  repetition
• Relational operators: ==, <, <=, >, >=, !=
• Logical expressions evaluate to 1 (true) or 0
  (false)
• Logical operators: ! (not), && (and), || (or)
• Two selection structures: one-way selection and
  two-way selection
• The expression in an if or if...else structure is
  usually a logical expression

                                                      34
Summary (continued)
• No stand-alone else statement in C++
   – Every else has a related if
• A sequence of statements enclosed between braces,
  { and }, is called a compound statement or block of
  statements
• Using assignment in place of the equality operator
  creates a semantic error
• switch structure handles multiway selection
• break statement ends switch statement
 Source:
 C++ Programming: From Problem Analysis to Program Design,
 Fourth Edition                                              35

More Related Content

What's hot

Conditional statements
Conditional statementsConditional statements
Conditional statements
cherrybear2014
 
Control statements in Java
Control statements  in JavaControl statements  in Java
Control statements in Java
Jin Castor
 

What's hot (20)

Control structure C++
Control structure C++Control structure C++
Control structure C++
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
C# conditional branching statement
C# conditional branching statementC# conditional branching statement
C# conditional branching statement
 
If and select statement
If and select statementIf and select statement
If and select statement
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
 
Control statements in java programmng
Control statements in java programmngControl statements in java programmng
Control statements in java programmng
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java Statements
 
Lecture 3 Conditionals, expressions and Variables
Lecture 3   Conditionals, expressions and VariablesLecture 3   Conditionals, expressions and Variables
Lecture 3 Conditionals, expressions and Variables
 
Control statements in Java
Control statements  in JavaControl statements  in Java
Control statements in Java
 
Selection statements
Selection statementsSelection statements
Selection statements
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statements
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
If-else and switch-case
If-else and switch-caseIf-else and switch-case
If-else and switch-case
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision Control
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
 
Object oriented programming16 boolean expressions and selection statements
Object oriented programming16 boolean expressions and selection statementsObject oriented programming16 boolean expressions and selection statements
Object oriented programming16 boolean expressions and selection statements
 
Vb decision making statements
Vb decision making statementsVb decision making statements
Vb decision making statements
 

Viewers also liked

Control Structures in Visual Basic
Control Structures in  Visual BasicControl Structures in  Visual Basic
Control Structures in Visual Basic
Tushar Jain
 
Selection Control Structures
Selection Control StructuresSelection Control Structures
Selection Control Structures
PRN USM
 
SE - Software Requirements
SE - Software RequirementsSE - Software Requirements
SE - Software Requirements
Jomel Penalba
 
05 control structures 2
05 control structures 205 control structures 2
05 control structures 2
Jomel Penalba
 
Ch5 - Project Management
Ch5 - Project ManagementCh5 - Project Management
Ch5 - Project Management
Jomel Penalba
 
Jedi course notes intro to programming 1
Jedi course notes intro to programming 1Jedi course notes intro to programming 1
Jedi course notes intro to programming 1
aehj02
 
Requirements Engineering Process
Requirements Engineering ProcessRequirements Engineering Process
Requirements Engineering Process
Jomel Penalba
 

Viewers also liked (20)

Iteration
IterationIteration
Iteration
 
Control Structures in Visual Basic
Control Structures in  Visual BasicControl Structures in  Visual Basic
Control Structures in Visual Basic
 
Control statements
Control statementsControl statements
Control statements
 
Selection Control Structures
Selection Control StructuresSelection Control Structures
Selection Control Structures
 
Business hardware
Business hardwareBusiness hardware
Business hardware
 
Crm
CrmCrm
Crm
 
SE - Software Requirements
SE - Software RequirementsSE - Software Requirements
SE - Software Requirements
 
05 control structures 2
05 control structures 205 control structures 2
05 control structures 2
 
Ch5 - Project Management
Ch5 - Project ManagementCh5 - Project Management
Ch5 - Project Management
 
06 procedures
06 procedures06 procedures
06 procedures
 
SE - System Models
SE - System ModelsSE - System Models
SE - System Models
 
12 gui concepts 1
12 gui concepts 112 gui concepts 1
12 gui concepts 1
 
Jedi course notes intro to programming 1
Jedi course notes intro to programming 1Jedi course notes intro to programming 1
Jedi course notes intro to programming 1
 
Pascal programming language
Pascal programming languagePascal programming language
Pascal programming language
 
Introduction to mobile communication
Introduction to mobile communicationIntroduction to mobile communication
Introduction to mobile communication
 
Control statement in c
Control statement in cControl statement in c
Control statement in c
 
Basic structure of C++ program
Basic structure of C++ programBasic structure of C++ program
Basic structure of C++ program
 
Control structure in c
Control structure in cControl structure in c
Control structure in c
 
Requirements Engineering Process
Requirements Engineering ProcessRequirements Engineering Process
Requirements Engineering Process
 
RPT Sains Komputer Tingkatan 4
RPT Sains Komputer Tingkatan 4RPT Sains Komputer Tingkatan 4
RPT Sains Komputer Tingkatan 4
 

Similar to Control structures selection

Copyright © 2018 Pearson Education, Inc.C H A P T E R 3.docx
Copyright © 2018 Pearson Education, Inc.C H A P T E R  3.docxCopyright © 2018 Pearson Education, Inc.C H A P T E R  3.docx
Copyright © 2018 Pearson Education, Inc.C H A P T E R 3.docx
dickonsondorris
 

Similar to Control structures selection (20)

Selection
SelectionSelection
Selection
 
CSC111-Chap_03.pdf
CSC111-Chap_03.pdfCSC111-Chap_03.pdf
CSC111-Chap_03.pdf
 
Understand Decision structures in c++ (cplusplus)
Understand Decision structures in c++ (cplusplus)Understand Decision structures in c++ (cplusplus)
Understand Decision structures in c++ (cplusplus)
 
Ch05.pdf
Ch05.pdfCh05.pdf
Ch05.pdf
 
ch05.ppt
ch05.pptch05.ppt
ch05.ppt
 
Control Structures, If..else, switch..case.pptx
Control Structures, If..else, switch..case.pptxControl Structures, If..else, switch..case.pptx
Control Structures, If..else, switch..case.pptx
 
Ch5 Selection Statements
Ch5 Selection StatementsCh5 Selection Statements
Ch5 Selection Statements
 
slides03.ppt
slides03.pptslides03.ppt
slides03.ppt
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
 
Week 1: Getting Your Hands Dirty - Part 1
Week 1: Getting Your Hands Dirty - Part 1Week 1: Getting Your Hands Dirty - Part 1
Week 1: Getting Your Hands Dirty - Part 1
 
Python Week 1.pptx
Python Week 1.pptxPython Week 1.pptx
Python Week 1.pptx
 
Lecture-13.ppt
Lecture-13.pptLecture-13.ppt
Lecture-13.ppt
 
0-Slot05-06-07-Basic-Logics.pdf
0-Slot05-06-07-Basic-Logics.pdf0-Slot05-06-07-Basic-Logics.pdf
0-Slot05-06-07-Basic-Logics.pdf
 
Control structure
Control structureControl structure
Control structure
 
Ch05-converted.pptx
Ch05-converted.pptxCh05-converted.pptx
Ch05-converted.pptx
 
C++ problem solving operators ( conditional operators,logical operators, swit...
C++ problem solving operators ( conditional operators,logical operators, swit...C++ problem solving operators ( conditional operators,logical operators, swit...
C++ problem solving operators ( conditional operators,logical operators, swit...
 
Intro To C++ - Class 09 - Control Statements: Part 1
Intro To C++ - Class 09 - Control Statements: Part 1Intro To C++ - Class 09 - Control Statements: Part 1
Intro To C++ - Class 09 - Control Statements: Part 1
 
Copyright © 2018 Pearson Education, Inc.C H A P T E R 3.docx
Copyright © 2018 Pearson Education, Inc.C H A P T E R  3.docxCopyright © 2018 Pearson Education, Inc.C H A P T E R  3.docx
Copyright © 2018 Pearson Education, Inc.C H A P T E R 3.docx
 
8 statement level
8 statement level8 statement level
8 statement level
 
Object oriented programming15 control structures relational operators
Object oriented programming15 control structures relational operatorsObject oriented programming15 control structures relational operators
Object oriented programming15 control structures relational operators
 

More from Online

More from Online (20)

Philosophy of early childhood education 3
Philosophy of early childhood education 3Philosophy of early childhood education 3
Philosophy of early childhood education 3
 
Philosophy of early childhood education 2
Philosophy of early childhood education 2Philosophy of early childhood education 2
Philosophy of early childhood education 2
 
Philosophy of early childhood education 1
Philosophy of early childhood education 1Philosophy of early childhood education 1
Philosophy of early childhood education 1
 
Philosophy of early childhood education 4
Philosophy of early childhood education 4Philosophy of early childhood education 4
Philosophy of early childhood education 4
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++
 
Functions
FunctionsFunctions
Functions
 
Formatted input and output
Formatted input and outputFormatted input and output
Formatted input and output
 
Control structures repetition
Control structures   repetitionControl structures   repetition
Control structures repetition
 
Introduction to problem solving in c++
Introduction to problem solving in c++Introduction to problem solving in c++
Introduction to problem solving in c++
 
Optical transmission technique
Optical transmission techniqueOptical transmission technique
Optical transmission technique
 
Multi protocol label switching (mpls)
Multi protocol label switching (mpls)Multi protocol label switching (mpls)
Multi protocol label switching (mpls)
 
Lan technologies
Lan technologiesLan technologies
Lan technologies
 
Introduction to internet technology
Introduction to internet technologyIntroduction to internet technology
Introduction to internet technology
 
Internet standard routing protocols
Internet standard routing protocolsInternet standard routing protocols
Internet standard routing protocols
 
Internet protocol
Internet protocolInternet protocol
Internet protocol
 
Application protocols
Application protocolsApplication protocols
Application protocols
 
Addressing
AddressingAddressing
Addressing
 
Transport protocols
Transport protocolsTransport protocols
Transport protocols
 
Leadership
LeadershipLeadership
Leadership
 
Introduction to management
Introduction to managementIntroduction to management
Introduction to management
 

Recently uploaded

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 

Recently uploaded (20)

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 

Control structures selection

  • 2. Objectives In this chapter, you will: • Learn about control structures • Examine relational and logical operators • Explore how to form and evaluate logical (Boolean) expressions • Discover how to use the selection control structures if, if...else, and switch in a program 2
  • 3. Control Structures • A computer can proceed: – In sequence – Selectively (branch) - making a choice – Repetitively (iteratively) - looping • Some statements are executed only if certain conditions are met • A condition is met if it evaluates to true 3
  • 5. Relational Operators • A condition is represented by a logical (Boolean) expression that can be true or false • Relational operators: – Allow comparisons – Require two operands (binary) – Evaluate to true or false 5
  • 7. Relational Operators (cont.) • You can use the relational operators with all three simple data types: – 8 < 15 evaluates to true – 6 != 6 evaluates to false – 2.5 > 5.8 evaluates to false – 5.9 <= 7.5 evaluates to true 7
  • 9. Logical (Boolean) Operators and Logical Expressions • Logical (Boolean) operators enable you to combine logical expressions unary binary binary 9
  • 10. Logical (Boolean) Operators and Logical Expressions (cont.) 10
  • 11. 11
  • 12. 12
  • 13. Order of Precedence • Relational and logical operators are evaluated from left to right • The associativity is left to right • Parentheses can override precedence 13
  • 14. Order of Precedence (cont.) 14
  • 15. Order of Precedence (cont.) 15
  • 16. Order of Precedence (cont.) 16
  • 17. Order of Precedence (cont.) 17
  • 18. Selection: if and if...else • One-Way Selection • Two-Way Selection • Compound (Block of) Statements • Multiple Selections: Nested if • Comparing if...else Statements with a Series of if Statements 18
  • 19. Selection: if and if...else (cont.) • The syntax of one-way selection is: • The statement is executed if the value of the expression is true • The statement is bypassed if the value is false; program goes to the next statement • if is a reserved word 19
  • 21. Two-Way Selection • Two-way selection takes the form: • If expression is true, statement1 is executed; otherwise, statement2 is executed – statement1 and statement2 are any C++ statements • else is a reserved word 21
  • 24. Compound (Block of) Statement • Compound statement (block of statements): • A compound statement is a single statement 24
  • 25. Compound (Block of) Statement (cont.) if (age > 18) { cout << "Eligible to vote." << endl; cout << "No longer a minor." << endl; } else { cout << "Not eligible to vote." << endl; cout << "Still a minor." << endl; } 25
  • 26. Multiple Selections: Nested if • Nesting: one control statement in another • An else is associated with the most recent if that has not been paired with an else 26
  • 27. 27
  • 28. Comparing if…else Statements with a Series of if Statements 28
  • 29. Confusion Between == and = • C++ allows you to use any expression that can be evaluated to either true or false as an expression in the if statement: if (x = 5) cout << "The value is five." << endl; • The appearance of = in place of == resembles a silent killer – It is not a syntax error – It is a logical error 29
  • 30. switch Structures • switch structure: alternate to if-else • switch (integral) expression is evaluated first • Value of the expression determines which corresponding action is taken • Expression is sometimes called the selector 30
  • 31. 31
  • 32. switch Structures (cont.) • One or more statements may follow a case label • Braces are not needed to turn multiple statements into a single compound statement • The break statement may or may not appear after each statement • switch, case, break, and default are reserved words 32
  • 33. 33
  • 34. Summary • Control structures alter normal control flow • Most common control structures are selection and repetition • Relational operators: ==, <, <=, >, >=, != • Logical expressions evaluate to 1 (true) or 0 (false) • Logical operators: ! (not), && (and), || (or) • Two selection structures: one-way selection and two-way selection • The expression in an if or if...else structure is usually a logical expression 34
  • 35. Summary (continued) • No stand-alone else statement in C++ – Every else has a related if • A sequence of statements enclosed between braces, { and }, is called a compound statement or block of statements • Using assignment in place of the equality operator creates a semantic error • switch structure handles multiway selection • break statement ends switch statement Source: C++ Programming: From Problem Analysis to Program Design, Fourth Edition 35