- Java Tutorial
- Java Introduction
- Java Features
- Java Simple Program
- JVM, JDK and JRE
- Java Syntax
- Java Comments
- Java Keywords
- Java Variables
- Java Literals
- Java Separators
- Java Datatypes
- Java Operators
- Java Statements
- Java Strings
- Java Arrays
- Control Statement
- Java If
- Java If-else
- Java If-else-if
- Java Nested If
- Java Switch
- Iteration Statement
- Java For Loop
- Java For Each Loop
- Java While Loop
- Java Do While Loop
- Java Nested Loop
- Java Break/Continue
- Java Methods
- Java Methods
- Java Method Parameters
- Java Method Overloading
- Java Recursion
- Java OOPS
- Java OOPs
- Java Classes/Objects
- Java Inheritance
- Java Polymorphism
- Java Encapsulation
- Java Abstraction
- Java Modifiers
- Java Constructors
- Java Interface
- Java static keyword
- Java this keyword
- Java File Handling
- Java File
- Java Create File
- Java Read/Write File
- Java Delete File
- Java Program To
- Add Two Numbers
- Even or Odd Numbers
- Reverse a String
- Swap Two Numbers
- Prime Number
- Fibonacci Sequence
- Palindrome Strings
- Java Reference
- Java String Methods
- Java Math Methods
Java For Loop
In Java, the for loop is used to iterate over a range of values or elements. Here's a concise overview:
Syntax:
for (initialization; condition; update) {
// Code to execute in each iteration
}
Initialization:
- Initializes the loop control variable.
- Executed only once before the loop starts.
Condition:
- Checked before each iteration. If false, the loop terminates.
Update:
- Modifies the loop control variable after each iteration.
- Typically increments or decrements the variable.
For Loop Example:
- Iterates over a range of values.
- Example:
for (int i = 0; i < 5; i++) {
System.out.println("Iteration " + (i + 1));
}
Summary
The for loop is a powerful construct for iterating over sequences of values or elements in Java. Understanding how to use for loops is fundamental for implementing repetitive tasks efficiently in Java programs.