ITERATIVE LOGIC
Course: Bachelor of Science / Engineering in Computer Science | Module 02:
Comprehensive Summary & Reference Sheet
1. Control Flow Taxonomy & Execution Paradigms
By default, a C program executes instructions sequentially from top to bottom. Control
flow statements alter this linear sequence based on boolean predicates evaluated at
runtime (where 0 denotes False and any non-zero integer denotes True).
±----------------------------------+
| C CONTROL FLOW CONSTRUCTS |
±----------------------------------+
|
±------------------------------±------------------------------+
|||
vvv
±----------------+ ±----------------+ ±----------------+
| SELECTION | | ITERATION | | JUMP |
| (Branching) | | (Loops) | | (Unconditional) |
±----------------+ ±----------------+ ±----------------+
| - if | | - while (Entry) | | - break |
| - if…else | | - for (Entry) | | - continue |
| - else-if ladder| | - do…while | | - goto |
| - switch…case | | (Exit-Ctrl) | | - return |
±----------------+ ±----------------+ ±----------------+
2. Conditional Selection & Branching Constructs
2.1 The if , if-else , and else-if Ladder
Used for arbitrary boolean range evaluations and compound relational expressions.
if (score >= 90) {
grade = ‘A’;
} else if (score >= 80) {
grade = ‘B’;
} else if (score >= 70) {
grade = ‘C’;
} else {
,grade = ‘F’;
}
Dangling-Else Resolution Rule: In nested conditional blocks without braces, an else
clause always binds to the nearest preceding unmatched if statement, regardless of
visual indentation.
Short-Circuit Evaluation: In if (ptr != NULL && *ptr > 0) , if ptr != NULL is false, the
right-hand dereference is skipped, preventing a segmentation fault.
2.2 Multi-Way Selection: switch…case
Provides constant-time (O(1)) jump-table dispatching for discrete integral expressions.
switch (expression) {
case CONSTANT_1:
// Statements for CONSTANT_1
break;
case CONSTANT_2:
case CONSTANT_3:
// Shared block via intentional fall-through
break;
default:
// Executed when no case label matches
break;
}
Architectural Criterion
if…else-if Ladder
switch…case Construct
Permitted Data Types
int , char , float , double , pointers
Integral types only ( int , char , enum )
Condition Complexity
Supports ranges ( x > 10 && x < 20 )
Strict equality against compile-time constants
Execution Mechanism
Sequential top-down evaluation (O(n))
Compiler-generated Jump Table (O(1))
Fall-Through Behavior
Mutually exclusive blocks
Falls through sequentially unless terminated by break
3. Iterative Constructs (Loops): Structural Comparison
Every deterministic loop requires four components: Initialization, Termination
Condition, Loop Body, and Update Expression.