Module 3: Control Structure - Selectors Flashcards
are used to control the flow of program execution by employing decision making, looping and branching, enabling your program to conditionally execute particular blocks of code
Control Structures
depends on the supplied data values and the conditional logic specified
Program Execution Order
Three Types of Control Statements
- Conditional/Selector Statement
- Iteration/Loop Statement
- Jump Statement
What are the conditional/selector statements?
- if statement
- if-else statement
- nested-if statement
- switch-case statement
What are the iteration/loop statements?
- for statement
- while statement
- do-while statement
What are the jump statements?
- break
- continue
decide which statement to execute and when
Selection/Decision Making Statement
Selection statements evaluate the _____ and control the program flow depending upon the result of the condition provided
Boolean expression
Three Types of Selection Statements
- Single Way Selection (if)
- Two Way Selection (if-else)
- Multiple Selection (nested if and switch-case)
- It is a simple decision-making statement
- It is used to decide whether the statement or block of statements should be executed or not
- Block of statements will be executed if the given condition is true otherwise the block of the statement will be skipped
Single Way Selection (If Statement)
Syntax for If Statement
Syntax: if (condition) { stmt1; stmt2; }
is an extension to the if-statement, which uses another block of code, i.e., else block
If-Else Statement
is executed if the condition of the if block is evaluated as false false
Else Block
Syntax for If-Else Statement
Syntax: if (condition) { stmt1; stmt2; } else { stmt3; stmt4; }
contains the if-statement followed by multiple else-if statements
Nested-If/If-Else-If Statement