



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
It serves as a comprehensive reference guide on how programs make decisions and execute distinct code blocks based on specified conditions. It introduces foundational relational operators for value comparison and logical operators for combining multiple conditions, illustrating each with clear evaluation results. The document outlines the syntax, structural templates, and practical code examples for essential C++ conditional logic, covering single if statements, alternative if-else branches, sequential if-else-if ladders, and nested if statements for secondary condition checks. Furthermore, it details the switch and nested switch control structures, demonstrating how they provide a cleaner alternative to long conditional ladders when evaluating variables against multiple constant values.
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Programs often need to make decisions and execute different code blocks based on certain conditions. This is achieved using decision control structures. RELATIONAL AND LOGICAL OPERATORS RELATIONAL OPERATOR
if (condition) { // Code to be executed if the condition is true }
Sunday, June 28, 2026 10:47 AM
int number = 10; If(number > 0) { cout << "The number is positive."; } IF-ELSE STATEMENT
int number = - 5; If(number >= 0) { cout << "Non - negative number."; } else { cout << "Negative number."; } // Output : Negative number. IF-ELSE-IF STATEMENT
int score = 85; char grade;
switch (expression) [ case constant1: // Code to be execute if expression == constant break; // Exit the switch block case constant2: // Code to execute if expression == constant break; // ….more cases….. default; // Code to execute if no case matches // The default case is optional. }
char op = ''; int a = 10, b = 5; switch (op0 { case '+': cout << a + b; break; case '-'; cout << a - b; break; case '': cout << a * b; // This will execute: 50 break; case '/': cout << a / b; break; default: cout << "Invalid operator!"; // Output : 50 NESTED SWITCH
switch(expression1) { case constantA: // Code for case constantA switch(expression2) { // Nested switch case constant X: // Code for nested case break; // …. Other nested cases… } break; // … other outer cases … }