Unit IV: Decision Making and Looping

Table of Contents

1. Decision Making and Branching

Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program. Branching allows the program to skip or execute certain blocks of code based on the result of these tests.


2. The IF Family

The if statement is the most powerful tool for controlling the flow of execution.


3. Switch Statement

The switch statement is a multi-way branch statement. It provides an easy way to dispatch execution to different parts of code based on the value of an expression.

Utility: It is often used as a cleaner alternative to a long else if ladder when comparing a single variable against multiple constant values.

4. Looping: Introduction and Types

Looping involves repeating a set of instructions until a specific condition is met. This is essential for tasks like processing array elements or generating series.


5. While, Do-While, and For Statements

There are three primary looping constructs in C:

Exam Tips


Frequently Asked Questions

Q1: What is the main difference between while and do-while?
The while loop may never execute if the condition is false initially, whereas do-while guarantees at least one execution.

Q2: When should I use an ELSE IF ladder over a Switch?
Use an else if ladder for range-based conditions (e.g., marks > 90) and a switch for specific discrete values (e.g., choice == 1).