Control Structure in C++
>Three different types of control structures
1. Sequential Structure
2. Selection Control Structure
3. Conditional Structure
Single alternative
● The "If" statement
– if condition with compound statement
● If-else condition
● if-else-if condition
>Program (sample prob 5-1 using if-else statement)
>Program (sample prob 5-1 using if-else statement)
> Sample Problem 5-2
● Program (Sample Problem 5-2)
> Sample Problem 5-3
● Program (Sample Problem 5-3)
3. The switch-case statement
● Break
> Sample Problem 5-4: Using switch-case statement
● Program (Sample Problem 5-4)
4. Loops/Repetition Statements
● These are two types of repetition statements:
– pretest repetition statement
– posttest repetition statement
5. For Statement
> Sample Problem 5-5: Using for statement
● Program (Sample Problem 5-5)
> Sample Problem 5-6: This program displays the string “Hello World” ten times.
● Program (Sample Problem 5-6)
6. while Statement
> Sample Problem 5-7: Using while statement
● Program (Sample Problem 5-7)
> Sample Problem 5-8: Using while statement
● Program (Sample problema 5-8)
7. The do-while loop
> Sample Problem 5-9: Using do-while
● Program (Sample Problem 5-9)
> Sample Problem 5-10: Using “do-while” and “if” statement
● Program (Sample Problem 5-10)
~Page 24