BCA Student Stories & UpdatesLive
Loops & Iteration: for, while, and for...of Statements
Loops automate repetitive tasks by executing a block of code multiple times until a specified termination condition is met. They are the backbone of algorithms, data processing, and DOM rendering.
Day 24 Step-by-Step Practical Flow
🎯1. What You Will Learn Today
Loops & Iteration: for, while, and for...of Statements — Comprehensive Practical Guide
Har concept ko visual mental models, code anatomy aur practical industry tips ke sath samjhein.
Loops automate repetitive tasks by executing a block of code multiple times until a specified termination condition is met. They are the backbone of algorithms, data processing, and DOM rendering.
"Think of a for loop like an automatic lap counter on an athletic track: Start at lap 0; check if laps < 10; run one lap; increase count by 1; stop when count reaches 10."
👨🏫3. Teacher Demonstration Code
See how loops calculate running sums and iterate over subject names without repetitive code.
<!DOCTYPE html>
<html>
<body>
<script>
// 1. Classic for loop: Sum 1 to 10
let totalSum = 0;
for (let i = 1; i <= 10; i++) {
totalSum += i;
}
console.log("Sum of 1 to 10:", totalSum); // 55
// 2. Modern for...of loop: Array traversal
const bcaSubjects = ["Computer Basics", "C Programming", "Discrete Math", "Communication"];
for (const subject of bcaSubjects) {
console.log("BCA Subject:", subject);
}
</script>
</body>
</html>2. Hands-On Practical Lab: Follow Instructions in VS Code
Code like a professional software engineer! Follow the step-by-step instructions below in Visual Studio Code (VS Code) on your PC, test your output locally, and push to GitHub.
Day 24 Practical Task Test Studio
Write a for loop with let i = 1 to i <= 10 printing i * 7 via console.log.
Iterate over the credits array using for (const credit of credits) and add each to totalCredits.
Spot the Bug: The Fatal Infinite Loop
Tap or click on the exact line below that contains the error:
Click any code linelet count = 5;while (count > 0) { console.log("Count is:", count); // Missing: count--; // Browser will freeze and crash!}Senior Developer Forensic Analysis:
Because count is never decremented, count > 0 remains true permanently, resulting in an infinite loop that maxes out CPU and crashes the browser tab.
📝Independent Practice: Assignment
📄 marks-analyzer.htmlStudent Marksheet Statistical Analyzer
- •Create day-24/index.html with an array of 6 student test scores.
- •Use a for loop to calculate the highest score, lowest score, and average marks.
- •Use a while loop to simulate an exam timer countdown from 10 to 0.
- •Display all calculated statistics cleanly in the DevTools console.
Open Visual Studio Code on your PC (code .), create marks-analyzer.html, paste this complete step-by-step verified code, test in your browser, and push to your GitHub repo:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BCA Day 24 - Student Marksheet Statistical Analyzer</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Segoe UI', Tahoma, sans-serif;
background: #0b1120;
color: white;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.analyzer-card {
background: #1e293b;
border: 1px solid #334155;
border-radius: 16px;
padding: 28px;
max-width: 500px;
width: 100%;
}
h1 { font-size: 20px; color: #38bdf8; margin-bottom: 12px; }
pre {
background: #0f172a;
padding: 16px;
border-radius: 8px;
font-size: 13px;
color: #34d399;
line-height: 1.6;
}
</style>
</head>
<body>
<div class="analyzer-card">
<h1>BCA Semester Marks Analyzer</h1>
<pre id="output">Running statistical loops...</pre>
</div>
<script>
// 6 Semester Subject Scores
const subjectMarks = [78, 85, 92, 64, 88, 71];
let sum = 0;
let highest = subjectMarks[0];
let lowest = subjectMarks[0];
// For Loop: Compute statistics
for (let i = 0; i < subjectMarks.length; i++) {
const score = subjectMarks[i];
sum += score;
if (score > highest) highest = score;
if (score < lowest) lowest = score;
}
const average = (sum / subjectMarks.length).toFixed(2);
// While Loop: Simulated Exam Timer Countdown
let timer = 5;
const countdownSteps = [];
while (timer > 0) {
countdownSteps.push(`Exam Timer: ${timer}s remaining...`);
timer--;
}
countdownSteps.push("Exam Timer: 0s - Time Up!");
const result = `Marks Array: [${subjectMarks.join(", ")}]
Total Marks Scored: ${sum}/600
Highest Subject Mark: ${highest}
Lowest Subject Mark: ${lowest}
Average Percentage: ${average}%
--------------------------------
${countdownSteps.join("\n")}`;
console.log(result);
document.getElementById("output").textContent = result;
</script>
</body>
</html>🎓4. Viva Check: Mandatory Conceptual Test
What is the main difference between a while loop and a do...while loop?
5. Mandatory Step: Push to GitHub to Unlock Next Lesson
Target Repo: html-css-projects
Exact GitHub Setup Guide & Expected Structure
Day 24 RequirementsFollow these exact folder and file names to prevent verification errors.
index.html: Avoid spaces or custom names like Alan Turing..html or Index.HTML. Linux/GitHub servers are strictly case-sensitive.day-24/ for today so you don't overwrite previous days.main.You are welcome to read all notes, inspect code snippets, and practice all exercises of Day 24 freely! To officially submit your GitHub repository and unlock subsequent days in your portfolio, please complete Day 23: Control Flow: Decision Making with if, else if, else & switch Statements first.
Complete Day 23 First