🚀 Day 28 of My Automation Journey – Nested For Loop

Spark Mantis
Thu, 02 Apr 2026 16:19:41 GMT
loops, java, automation, beginners

Today’s learning was super important 👇 👉 Moving from single loops → nested loops 👉 This is where pattern logic begins 🔥 🔹 1. What is a Nested Loop? 👉 A loop inside another loop is called a nested loop 💡 Structure: for(row) { for(column) { // logic } } 🧠 How It Works 👉 Outer loop → controls rows 👉 Inner loop → controls columns 🔹 2. Basic Example (Print 1’s) for(int row = 1; row <= 2; row++) { for(int col = 1; col <= 5; col++) { System.out.print(1); } System.out.println(); } 📤 Output: 11111 11111 🔹 3. Print Row Number for(int row = 1; row <= 2; row++) { for(int col = 1; col <= 5; col++) { System.out.print(row); } System.out.println(); } 📤 Output: 11111 22222 🔹 4. Print Column Number for(int row = 1; row <= 2; row++) { for(int col = 1; col <= 5; col++) { System.out.print(col); } System.out.println(); } 📤 Output: 12345 12345 🔹 5. Rectangle Pattern ⭐ for(int row = 1; row <= 3; row++) { for(int col = 1; col <= 5; col++) { System.out.print("*"); } Syst