C++_Control_Statements_Flowcharts
C++_Control_Statements_Flowcharts
Statements
Flowcharts, Syntax & Programs for Each Type
Introduction
• Types:
• - Selection Statements (if, if-else, switch)
• - Iteration Statements (for, while, do-while)
• - Jump Statements (break, continue, goto, return)
Selection: If-Else Statement
• **Syntax:**
• if (condition) {
• // Code when true
• } else {
• // Code when false
• }
• **Example Program:**
• int num = 10;
• if (num > 0) {
• cout << 'Positive';
• } else {
• cout << 'Negative';
• }
Selection: Switch Statement
• **Syntax:**
• switch (expression) {
• case value1: // Code
• break;
• default: // Code
• }
• **Example Program:**
• int day = 2;
• switch (day) {
• case 1: cout << 'Monday'; break;
• case 2: cout << 'Tuesday'; break;
• default: cout << 'Other Day';
• }
Iteration: For Loop
• **Syntax:**
• for (init; condition; update) {
• // Code
•}
• **Example Program:**
• for (int i = 0; i < 5; i++) {
• cout << i;
•}
Iteration: While Loop
• **Syntax:**
• while (condition) {
• // Code
• }
• **Example Program:**
• int i = 0;
• while (i < 5) {
• cout << i;
• i++;
• }
Iteration: Do-While Loop
• **Syntax:**
• do {
• // Code
• } while (condition);
• **Example Program:**
• int i = 0;
• do {
• cout << i;
• i++;
• } while (i < 5);
Jump Statements
• **Example:**
• for (int i = 0; i < 5; i++) {
• if (i == 3) break;
• cout << i;
•}
Conclusion