0% found this document useful (0 votes)
8 views

For Loop in Java

Explanation of for loop

Uploaded by

Vasanthakumar N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

For Loop in Java

Explanation of for loop

Uploaded by

Vasanthakumar N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

For Loop in Java

1. Introduction

- Purpose of loops in programming.

- Overview of the 'for' loop.

2. Syntax of a For Loop

General structure:

for (initialization; condition; update) {

// Code block to execute

3. Types of For Loops

- Simple For Loop: Iterating a fixed number of times.

- Nested For Loops: Using a loop inside another loop.

- Enhanced For Loop (For-Each Loop): Iterating through arrays and collections.

4. Examples

- Printing numbers from 1 to 10.

- Summing up elements of an array.

- Generating a multiplication table.

- Displaying patterns (e.g., triangles, squares).

5. Common Mistakes
- Infinite loops.

- Off-by-one errors.

- Modifying a collection during iteration.

6. Use Cases and Applications

- Iterating over arrays or lists.

- Repeating tasks a fixed number of times.

7. Practice Exercises

- Write a program to find the factorial of a number using a 'for' loop.

- Create a pattern using nested 'for' loops.

- Calculate the sum of odd numbers between 1 and 50.

You might also like