Unit 3Decision and Loop Control Statements
Follows IGNOU MCS-201, Unit 3
Without control statements, a program would run every statement exactly once, from top to bottom. Real programs must choose between actions (is the marks value a pass or a fail?) and repeat work (process every invoice in a list). This unit covers the C statements that make decisions and loops, the two ideas behind almost every algorithm you will write, together with the jump statements that alter the normal flow.
In this unit you will learn to
- Make decisions with
if,if–else, nestedifand theelse ifladder. - Choose among many fixed values with
switch, and control fall-through withbreak. - Repeat work with
while,do–whileandforloops, and choose the right loop for a task. - Write nested loops to produce tables and patterns.
- Use
break,continueandgoto, and know when to avoid them. - Trace programs that use decisions and loops and predict their exact output.
Sections in this unit
- 3.1Control Statements and the if StatementLearn what control statements are, and make simple decisions in C with the if and if-else statements.10 min
- 3.2Nested if and the else-if LadderHandle more than two outcomes with nested if statements and the else-if ladder, and resolve the dangling-else rule.8 min
- 3.3The switch StatementSelect among many fixed integer values with switch, and understand case labels, break, fall-through and default.11 min
- 3.4The while and do-while LoopsRepeat statements with the entry-controlled while loop and the exit-controlled do-while loop, and trace loops to predict their output.8 min
- 3.5The for LoopWrite counting loops with for, understand the order of its three parts, use optional parts, and choose between for, while and do-while.7 min
- 3.6Nested LoopsPlace one loop inside another to process rows and columns, and use nested loops to print tables and number patterns.8 min
- 3.7Jump Statements: break, continue and gotoLeave a loop early with break, skip to the next iteration with continue, and understand goto with labels and why it is avoided.10 min