• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 8 pages
Class notes

C Programming Comprehensive Lecture Notes: Decision Making, Iterative Constructs, Loop Control & Algorithmic Tracing

Document preview thumbnail
Preview 2 out of 8 pages

Extensive university-grade C Programming Module 02 lecture notes for Computer Science students. Includes formal control flow theory, structured selection syntax, jump-table mechanics for switch statements, complete iteration anatomy, sentinel vs. counter-controlled loops, step-by-step variable trace tables, nested loop complexity analysis, and fully solved university examination programs.

Content preview

LECTURE NOTES: CONTROL FLOW, ITERATION &
ALGORITHMIC TRACING
Course: CS-101 Fundamentals of Programming in C | Module 02: Comprehensive
Lecture & Class Notes




1. Foundations of Structured Control Flow
According to the Böhm–Jacopini Structured Program Theorem, any computable
algorithm can be expressed using three fundamental control structures: Sequence,
Selection, and Iteration.
1.1 Boolean Truth Representation in C
Historically, ANSI C89 lacked a dedicated boolean primitive. Consequently, all conditional
expressions evaluate to an integer of type int :
Logical False: Strictly integer zero ( 0 ), floating-point zero ( 0.0 ), or the null pointer
( NULL ).
Logical True: Any non-zero value (positive or negative, such as 1 , -5 , or 42 ).
Relational and logical operators ( == , != , < , && , || ) are guaranteed by the C
standard to yield strictly 1 or 0 .

2. Selection Statements & Branching Mechanics
2.1 Single-Alternative and Dual-Alternative Selection
[ Evaluate Condition ]
/
True / \ False
vv
±---------------+ ±---------------+
| True Branch | | False Branch |
| Statement(s) | | Statement(s) |
±---------------+ ±---------------+
\/
vv
[ Next Statement ]
Syntax & Block Scoping
if (condition_expression) {
// Compound statement block (executes if condition_expression != 0)
} else {

,// Alternative compound block (executes if condition_expression == 0)
}


Scope Rule (C99/C11): Variables declared inside an if or else compound block
possess block scope and automatic storage duration; their memory is reclaimed
immediately upon exiting the closing brace } .


2.2 Multi-Alternative Selection: The else-if Ladder
When testing mutually exclusive conditions sequentially, the else-if ladder guarantees
that once the first true condition is encountered, its associated block executes and all
remaining branches are bypassed:
#include <stdio.h>

int main(void) {
double units, bill;
printf(“Enter electricity units consumed: “);
scanf(”%lf”, &units);


if (units <= 100.0) {
bill = units * 1.50;
} else if (units <= 200.0) {
bill = (100.0 * 1.50) + ((units - 100.0) * 2.50);
} else if (units <= 300.0) {
bill = (100.0 * 1.50) + (100.0 * 2.50) + ((units - 200.0) * 4.00);
} else {
bill = (100.0 * 1.50) + (100.0 * 2.50) + (100.0 * 4.00) + ((units - 300.0) * 6.00);
}


printf("Total Payable Bill: $%.2lf\n", bill);
return 0;


}
2.3 Multi-Way Dispatch: The switch…case Statement
The switch statement evaluates an integral control expression once and transfers
control directly to the matching case constant label.
Formal Syntax Constraints
Control Expression: Must undergo integer promotion to int , long , char , or enum .
Floating-point types ( float , double ) and strings ( char* ) produce a compile-time error.
Case Labels: Each case label must be a unique compile-time constant expression
(e.g., case 10: or case ‘A’: ). Variable identifiers (e.g., case x: ) are illegal in standard C.

Document information

Uploaded on
November 25, 2026
Number of pages
8
Written in
2026/2027
Type
Class notes
Professor(s)
General / standard curriculum
Contains
For all classes
$7.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
0
Followers
0
Items
8
Last sold
-



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions