C++ Decision Control Structures & Operators, Study notes of Programming Languages

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

2025/2026

Available from 06/28/2026

rissa-mae-cacayan
rissa-mae-cacayan 🇵🇭

2 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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
Used to compare 2 values
-
OPERATOR
EXAMPLE
RESULT(If A=5, B=10)
==
A == B
!=
A != B
>
A > B
<
A < B
>=
A >= B
<=
A <= B
LOGICAL OPERATOR
Used to combine multiple simple values
-
OPERATOR
MEANING
DESCRIPTION
&&
LOGICAL AND
TRUE ONLY IF ALL CONDITIONS ARE TRUE
II
LOGICAL OR
TRUE IF AT LEAST ONE CONDITION
!
LOGICAL NOT
REVERSES THE LOGICAL STATE OF OPERAND
Example: (if A = 5, b = 10, c = 15)
(A < B) && (B < C) // true
(A > B) II (B < C) // true
! (A == B) // true
IF CONTROL STRUCTURE
The if statement is used to execute a block of code only if a specified
conditions is true.
-
TEMPLATE:
if (condition) {
// Code to be executed if the condition is true
}
-----
DECISION CONTROL STRUCTURES - C++
Language
Sunday, June 28, 2026
10:47 AM
Quick Notes Page 1
pf3
pf4
pf5

Partial preview of the text

Download C++ Decision Control Structures & Operators and more Study notes Programming Languages in PDF only on Docsity!

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

  • Used to compare 2 values OPERATOR EXAMPLE RESULT( If A=5, B=10) == A == B FALSE != A != B TRUE > A > B FALSE < A < B TRUE >= A >= B FALSE <= A <= B TRUE LOGICAL OPERATOR
  • Used to combine multiple simple values OPERATOR MEANING DESCRIPTION && LOGICAL AND TRUE ONLY IF ALL CONDITIONS ARE TRUE II LOGICAL OR TRUE IF AT LEAST ONE CONDITION ! LOGICAL NOT REVERSES THE LOGICAL STATE OF OPERAND Example: (if A = 5, b = 10, c = 15) (A < B) && (B < C) // true (A > B) II (B < C) // true ! (A == B) // true IF CONTROL STRUCTURE The if statement is used to execute a block of code only if a specified conditions is true.

TEMPLATE:

if (condition) { // Code to be executed if the condition is true }

DECISION CONTROL STRUCTURES - C++

Language

Sunday, June 28, 2026 10:47 AM

int number = 10; If(number > 0) { cout << "The number is positive."; } IF-ELSE STATEMENT

  • Provides an alternative block of code to execute if the condition is false. TEMPLATE: if(condition) { // Code if condition is true } else { // Code if condition is false }

int number = - 5; If(number >= 0) { cout << "Non - negative number."; } else { cout << "Negative number."; } // Output : Negative number. IF-ELSE-IF STATEMENT

  • Checks multiple conditions in sequence. TEMPLATE: if(condition1) { // Code if condition1 is true } else if {condition2) { // Code if condition2 is true } else { // Code if all above conditions are false }

int score = 85; char grade;

TEMPLATE:

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

  • A switch statement can be inside another switch statement.

TEMPLATE:

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 … }