CONTROL STATEMENTS IN C++ TRB CSI › Programming with C++ › control statements

CONTROL STATEMENTS IN C++

Control Statements என்பது program-ன் flow of execution-ஐ control செய்யும் statements. Simple definition: Control statements determine the order in which program statements are executed. Normally C++ program: Statement 1 ↓ Statement 2 ↓ Sta…

Premium — locked Advanced 32 min 193 cards 45 programs 11 MCQs v2
This is a premium lesson. You can see the shape of every card — unlock to read them. Unlock

CONTROL STATEMENTS IN C++…

Premium This card is part of the premium lesson. Unlock
Definition

Control Statements என்பது program-ன் flow of execution-ஐ control செய்யும் statements. Simple definition: Cont……

Premium This card is part of the premium lesson. Unlock
Real Life Example
Real-life example

நீங்கள் college gate-க்கு வருகிறீர்கள். Rule: If ID card is ……

Premium This card is part of the premium lesson. Unlock
Explanation
Why control statements are needed

Suppose: cout = 40 → Pass Marks < 4……

Premium This card is part of the premium lesson. Unlock
Explanation
Main types of control statements

C++ control statements முக்கியமாக மூன்று categories: Control Statemen……

Premium This card is part of the premium lesson. Unlock

SELECTION / DECISION CONTROL STATEMENTS

Explanation

Condition அடிப்படையில் எந்த block execute செய்ய வேண்……

Premium This card is part of the premium lesson. Unlock
Definition

Condition true என்றால் மட்டும……

Premium This card is part of the premium lesson. Unlock
Explanation

Flow: Condition / \ True Fals……

Premium This card is part of the premium lesson. Unlock
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock
Explanation

int age = 20; age variable-ல் 20 store செய்கிறோம……

Premium This card is part of the premium lesson. Unlock
Real Life Example
If false example

int age = 15; if (age >= 18) ……

Premium This card is part of the premium lesson. Unlock
Important

if condition-ன் result Boolea……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

True.…

Premium This card is part of the premium lesson. Unlock
Explanation

False.…

Premium This card is part of the premium lesson. Unlock

IF-ELSE STATEMENT

Definition

Condition true என்றால் one bl……

Premium This card is part of the premium lesson. Unlock
Flow

Condition / \ True False | | ……

Premium This card is part of the premium lesson. Unlock
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock
Dry Run
marks = 35
Important

if-else-ல் only one block execu……

Premium This card is part of the premium lesson. Unlock

ELSE-IF LADDER

Definition

Multiple conditions check செய……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

90+ → Grade A 75+ → Grade B 5……

Premium This card is part of the premium lesson. Unlock
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock
Dry Run
marks = 82
Important

else-if ladder top-to-bottom check ……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

int marks = 95;…

Premium This card is part of the premium lesson. Unlock

Why? First condition: 95 >= 50 → true அதனால் se……

Premium This card is part of the premium lesson. Unlock

NESTED IF

Definition

ஒரு if statement-க்குள் anoth……

Premium This card is part of the premium lesson. Unlock
Real Life Example
Real-life example

Job eligibility: Age >= 18 ↓ Qualification available……

Premium This card is part of the premium lesson. Unlock
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock
Dry Run
age = 22 marks = 70
Explanation
Nested if-else

if (age >= 18) { if (marks >=……

Premium This card is part of the premium lesson. Unlock
Concept
Common dangling else concept

Consider: if (a > 0) if (b > ……

Premium This card is part of the premium lesson. Unlock

SWITCH STATEMENT

Definition

One expression-ன் value அடிப்படையில் பல a……

Premium This card is part of the premium lesson. Unlock
Explanation
Syntax

switch (expression) { case value1: stateme……

Premium This card is part of the premium lesson. Unlock
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock
Explanation
How switch works

day = 2 Compiler checks: case 1 → no case 2 →……

Premium This card is part of the premium lesson. Unlock
Explanation
Break in switch

break இல்லாமல் விட்டால் fall-……

Premium This card is part of the premium lesson. Unlock

Why? case 1 match ஆன பிறகு break……

Premium This card is part of the premium lesson. Unlock
Explanation
Default

No case match ஆனபோது default execute ஆகும்.……

Premium This card is part of the premium lesson. Unlock
Program
Example better with if
Explanation

Example better with switch: s……

Premium This card is part of the premium lesson. Unlock

ITERATION / LOOPING CONTROL STATEMENTS

Explanation

ஒரே statements repeatedly execute ச……

Premium This card is part of the premium lesson. Unlock
Explanation
Why loop

Without loop: cout…

Premium This card is part of the premium lesson. Unlock

FOR LOOP

Definition

Number of repetitions roughly……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation
For loop components

for (int i = 1; i…

Premium This card is part of the premium lesson. Unlock
Flow

Initialization ↓ Condition / \ t……

Premium This card is part of the premium lesson. Unlock
Dry Run
for (int i = 1; i <= 3; i++) { cout << i; }

WHILE LOOP

Definition

Condition true இருக்கும் வரை ……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

int i = 1;…

Premium This card is part of the premium lesson. Unlock
Flow
While flow

Condition / \ true false | | ……

Premium This card is part of the premium lesson. Unlock
Important

while is an entry-controlled loop. Why? Condition body execut……

Premium This card is part of the premium lesson. Unlock

DO-WHILE LOOP

Definition

do-while loop body first exec……

Premium This card is part of the premium lesson. Unlock
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock
Important

do-while is exit-controlled loop. Because condition ……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

int x = 10;…

Premium This card is part of the premium lesson. Unlock

Condition false இருந்தாலும் b……

Premium This card is part of the premium lesson. Unlock

[FOR vs WHILE]…

Premium This card is part of the premium lesson. Unlock

JUMP CONTROL STATEMENTS

Program flow-ஐ suddenly chang……

Premium This card is part of the premium lesson. Unlock
Important

break continue return goto…

Premium This card is part of the premium lesson. Unlock

BREAK STATEMENT

Definition

break nearest loop அல்லது swi……

Premium This card is part of the premium lesson. Unlock
Program
Example
Definition

continue current iteration-ன் remain……

Premium This card is part of the premium lesson. Unlock
Program
Example

3 மட்டும் skip செய்யப்படுகிறது. [BREAK vs CONTINUE] Very impor……

Premium This card is part of the premium lesson. Unlock
Program
Example

RETURN STATEMENT

Definition

return function execution-ஐ e……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

int add(int a, int b) { return a +……

Premium This card is part of the premium lesson. Unlock
Explanation
Main function return

int main() { return 0; } return 0 gen……

Premium This card is part of the premium lesson. Unlock
Explanation
Return early

int main() { int age = 15; if……

Premium This card is part of the premium lesson. Unlock

GOTO STATEMENT

Definition

goto control-ஐ ஒரு labeled st……

Premium This card is part of the premium lesson. Unlock
Explanation
Syntax

goto label; label: statement;…

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock
Important
Important about goto

goto C++-ல் available. ஆனால் modern structured programming-ல் generally avoid செய்வது……

Premium This card is part of the premium lesson. Unlock
Explanation
Control statements complete classification

CONTROL STATEMENTS │ ├── Selection / Decision │ ├── if │ ├── if-else │ ├── else-if ladder │ ├……

Premium This card is part of the premium lesson. Unlock
Explanation
Sequential control

One more basic concept. Norma……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Common error 1 - semicolon after if

Wrong: if (x > 5); { cout 5); semicolon condition-ஐ empty stat……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Common error 3 - infinite loop

int i = 1; while (i…

Premium This card is part of the premium lesson. Unlock
Common Mistake
Common error 4 - do-while semicolon

Correct: do { cout…

Premium This card is part of the premium lesson. Unlock
Common Mistake
Common error 5 - switch without break

switch (x) { case 1: cout…

Premium This card is part of the premium lesson. Unlock
Common Mistake
Common error 6 - wrong else-if order

Wrong logical order: if (mark……

Premium This card is part of the premium lesson. Unlock
Program
Better

means: Exit completely continue……

Premium This card is part of the premium lesson. Unlock
Comparison
Important comparison
Comparison

[ENTRY vs EXIT CONTROLLED LOOP] Entry Controlled Condition fir……

Premium This card is part of the premium lesson. Unlock
Memory Trick

Three main categories: S I J S → Selection I → Iteration J → ……

Premium This card is part of the premium lesson. Unlock
TRB Point

What are control statements? Control statements are st……

Premium This card is part of the premium lesson. Unlock
TRB Point
C++ control statements

1. Selection statements 2. It……

Premium This card is part of the premium lesson. Unlock
TRB Point
Trb point - important

Which is an entry-controlled loop……

Premium This card is part of the premium lesson. Unlock
TRB Point
Trb point - important

break Terminates the nearest enclosing loop or switch. continue……

Premium This card is part of the premium lesson. Unlock
Interview Point

Difference between if and switch? if: if (marks >= 50) Supports ranges an……

Premium This card is part of the premium lesson. Unlock
Interview Point

Difference between while and do-while? while: Conditio……

Premium This card is part of the premium lesson. Unlock
Interview Point

What is fall-through in switch? When a matching c……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

For x = 1: AB…

Premium This card is part of the premium lesson. Unlock
MCQ

Which statement is used for d……

Premium This card is part of the premium lesson. Unlock
MCQ

Which is an iteration stateme……

Premium This card is part of the premium lesson. Unlock
MCQ

Which is an exit-controlled l……

Premium This card is part of the premium lesson. Unlock
MCQ

Which statement immediately t……

Premium This card is part of the premium lesson. Unlock
MCQ

Which statement skips only th……

Premium This card is part of the premium lesson. Unlock
MCQ

Which statement is best suite……

Premium This card is part of the premium lesson. Unlock
MCQ

A do-while loop executes:…

Premium This card is part of the premium lesson. Unlock
MCQ

Which operator is normally us……

Premium This card is part of the premium lesson. Unlock
MCQ

break in a switch is used to:…

Premium This card is part of the premium lesson. Unlock
MCQ

Which one is a jump statement?…

Premium This card is part of the premium lesson. Unlock
MCQ

Which loops are entry-control……

Premium This card is part of the premium lesson. Unlock
Dry Run
Practice - dry run
Practice
Practice 2

int i = 1; while (i…

Premium This card is part of the premium lesson. Unlock
Practice
Practice 3

int i = 10; do { cout…

Premium This card is part of the premium lesson. Unlock

Reason: do-while body execute……

Premium This card is part of the premium lesson. Unlock
Summary

Control Statements Control statements control the order and flow of execution of a C++ program. Three importa……

Premium This card is part of the premium lesson. Unlock
Text size
17px
Theme
Contents
Print / PDF
Program