Open links in new tab
    • Work Report
    • Email
    • Rewrite
    • Speech
    • Title Generator
    • Smart Reply
    • Poem
    • Essay
    • Joke
    • Instagram Post
    • X Post
    • Facebook Post
    • Story
    • Cover Letter
    • Resume
    • Job Description
    • Recommendation Letter
    • Resignation Letter
    • Invitation Letter
    • Greeting Message
    • Try more templates
  1. The for loop in Java is a control flow statement that allows code to be executed repeatedly based on a given condition. It is commonly used for iterating over a range of values, executing code multiple times, or traversing arrays and collections.

    Syntax

    for (initialization; condition; update) {
    // body of the loop
    }
    Copied!

    Example: Printing Numbers from 1 to 5

    public class Main {
    public static void main(String[] args) {
    for (int i = 1; i <= 5; i++) {
    System.out.println(i);
    }
    }
    }
    Copied!

    Output:

    1
    2
    3
    4
    5
    Copied!

    Explanation:

    1. Initialization: int i = 1; - This sets the starting point of the loop.

    2. Condition: i <= 5; - The loop runs as long as this condition is true.

    3. Update: i++ - This increments the loop variable after each iteration.

    Example: Printing Even Numbers from 0 to 10

    public class Main {
    public static void main(String[] args) {
    for (int i = 0; i <= 10; i += 2) {
    System.out.println(i);
    }
    }
    }
    Copied!

    Output:

    0
    2
    4
    6
    8
    10
    Copied!

    Nested For Loop Example: Printing a Matrix-like Pattern^2^

    Feedback
  2. Java Loops - GeeksforGeeks

    Aug 10, 2025 · In Java, there are three types of Loops, which are explained below: The for loop is used when we know the number of iterations (we know how many …

  3. Java for Loop (With Examples) - Programiz

    Java for loop is used to run a block of code for a certain number of times. The syntax of forloop is: Here, 1. The initialExpression initializes and/or declares variablesand executes only once. 2. The condition is evaluated. If the condition is true, the body of the forloop is executed. 3. The updateExpression updates the value of initialExpression...
    See more on programiz.com
  4. The for Statement (The Java™ Tutorials > Learning the Java ... - Oracle

    Programmers often refer to it as the "for loop" because of the way in which it repeatedly loops until a particular condition is satisfied. The general form of the for statement can be expressed as follows:

  5. Java - for Loop - Online Tutorials Library

    In Java, a for loop is a repetition control structure used to execute a block of code a specific number of times. It is particularly useful when the number of iterations is …

  6. Java For Loop - Baeldung

    Feb 25, 2026 · In this article, we’ll look at a core aspect of the Java language – executing a statement or a group of statements repeatedly using a for loop. 2. …

  7. Java Loops - programguru.org

    Loops in Java are designed to help you automate repetitive actions with control. In this tutorial, we’ll walk through all types of Java loops, when to use them, and how to write and understand their …

  8. For Loop in Java | Full Explanation with Examples, Errors ... - YouTube

    1 day ago · For Loop in Java full explanation for beginners with examples, problems, mistakes, and interview questions. In this Java tutorial, you will learn for loop in...

    • Author: ADV Indian Coder
    • Views: 2
  9. Java For Loop, For-Each Loop, While, Do-While Loop …

    In this tutorial, we’ll cover the four types of loops in Java: the for loop, enhanced for loop (for-each), while loop and do-while loop. We’ll also cover loop control flow …

  10. Java Loops | Java Tutorial Network

    Jan 6, 2015 · This tutorial explains how Java loops are created and how did they work. Very often you will want to execute code fragments in your programs several times until some conditions are met.