TaleemBay
Study
UniversitiesScholarshipsFeesDates
TaleemBay

Empowering students with Next-Gen tools for a brighter future. Your one-stop destination for education in Pakistan.

Quick Links

  • Universities
  • Study Center
  • Past Papers
  • Date Sheets
  • Results

Support

  • About Us
  • Contact
  • Privacy Policy
  • Terms of Service
  • Advertise

Contact Us

  • Arfa Software Technology Park,
    Ferozepur Road, Lahore
  • +92 300 1234567
  • hello@taleembay.com

© 2026 TaleemBay. All rights reserved.

Designed with ❤️ for Pakistan

Home
Unis
Study

Study Center

Overview
9th Class10th Class11th Class12th Class

Resources

Past PapersDate Sheets

Need Notes?

AI-powered search for instant answers.

Chapter 12
computer-science • intermediate 12th

Chapter 12: Loop Constructs

Comprehensive notes for Chapter 12 Loop Constructs. Covers while, do-while, for loops, nested loops, break, continue, and goto statements.

Loop Basics

Definition: A statement or set of statements executed repeatedly is known as a loop. Also called iterative or repetitive structure.

  • Counter-Controlled Loop: Number of iterations is known in advance. Uses a counter variable (e.g., for loop).
  • Sentinel-Controlled Loop: Number of iterations is unknown. Terminates when a special value (sentinel) is encountered (e.g., while loop reading input until -1).

while Loop

Definition: Simplest loop. Executes executed one or more statements while the given condition remains true. Useful when iterations are unknown.

Syntax: while (condition) { statement(s); }

Condition is checked before execution. If false initially, loop never executes.

do-while Loop

Definition: Executes statements while a condition is true, but checks the condition after the body.

Syntax: do { statement(s); } while (condition);

Key Feature: Guaranteed to execute at least once, even if the condition is false initially.

for Loop

Definition: Most flexible loop, normally used when iterations are known (Counter-Controlled).

Syntax: for (initialization; condition; increment/decrement) { statement(s); }

  • Initialization: Sets starting value (executed once).
  • Condition: Checked before each iteration.
  • Increment/Decrement: Updates counter after each iteration.

Nested Loop

Definition: A loop inside another loop. The inner loop completes all its iterations for each single iteration of the outer loop.

Example: Clock logic (inner loop for seconds, outer loop for minutes).

Loop Control Statements

  • break: Immediately exits the loop. Control moves to the statement following the loop.
  • continue: Skips the remaining statements in the current iteration and moves to the start of the next iteration.
  • goto: Translers control unconditionally to a labeled statement. Use is generally discouraged as it makes code hard to follow.