Search
  • +44-7459919437 (UK- WhatsApp & Direct Call) | +91-6383544892 (India - WhatsApp Only) | Email Id : vinothrwins@gmail.com
Vinoth Tech Solutions
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I

Java For Automation

  • What is Java?
  • Why to Learn Java?
  • History of Java
  • Types of Java Applications
  • Naming Conventions
  • Hello World Program
  • Internal Details of Java program
  • What is Java JDK, JRE and JVM ?
  • What is Java Comments ?
  • What is Java Variable?
  • Variable Naming convention
  • Primitive Data Types
  • Non Primitive Data Types
  • Type Casting
  • Java Arithmetic Operators
  • Relational Operators
  • What is logical operators in Java? 
  • What is Assignment Operators in Java? 
  • What is Unary Operators in Java? 
  • What is Ternary Operators in Java?
  • What is Java Control Statements?
  • What are Decision Making statements?
  • What are looping statements?
  • What are Jump statements?
  • What is OOPS concept in Java?
  • Advantages of Java OOPs
  • What is Java Inheritance?
  • What is Java Constructor?
  • What is this keyword?
  • What is Polymorphism?
  • What is super keyword ?
  • What is final keyword? 
  • What are access modifiers?
  • What is Encapsulation? 
  • What is Abstraction? 
View Categories
  • Home
  • Tutorials
  • Java
  • Java For Automation
  • What are looping statements?

What are looping statements?

What are looping statements?

Looping statements are used to execute a block of code repeatedly based on a condition.

1. for Loop: Executes a block of code a specific number of times.

Example : for Loop #

public class ForLoopExample {

    public static void main(String[] args) {

        for (int i = 1; i <= 5; i++) {

            System.out.println("i = " + i);

        }

    }

}

Output:
i = 1
i = 2
i = 3
i = 4
i = 5

The for loop executes the block of code five times, incrementing i each time.

2. while Loop: Repeatedly executes a block of code as long as the condition is true.

Example : while Loop #

public class WhileLoopExample {

    public static void main(String[] args) {

        int i = 1;

        while (i <= 5) {

            System.out.println("i = " + i);

            i++;

        }

    }

}

Output:
i = 1
i = 2
i = 3
i = 4
i = 5

The while loop keeps executing as long as i is less than or equal to 5.

3. do-while Loop: Similar to the while loop, but the block of code is executed at least once, even if the condition is false.

Example : do-while Loop #

public class DoWhileExample {

    public static void main(String[] args) {

        int i = 1;

        do {

            System.out.println("i = " + i);

            i++;

        } while (i <= 5);

    }

}

Output:
i = 1
i = 2
i = 3
i = 4
i = 5

The do-while loop ensures that the code block runs at least once.

Java
What are your Feelings
Share This Article :
  • Facebook
  • X
  • LinkedIn
What are Decision Making statements?What are Jump statements?
Table of Contents
  • Example : for Loop
  • Example : while Loop
  • Example : do-while Loop
© 2018 – 2025 Vinoth Tech Solutions Ltd (UK), Reg. No: 16489105