Loops in Java: for, while, do-while

 Quality Thought is recognized as the best software testing institute in Hyderabad, offering top-notch training in manual testing, automation testing, and full stack testing tools. With a focus on industry-relevant curriculum and hands-on practice, Quality Thought prepares students for real-world software testing challenges. The institute provides expert-led training on popular tools and frameworks like Selenium, TestNG, Jenkins, Git, Postman, JIRA, Maven, and Cucumber, covering both frontend and backend testing essentials.


Quality Thought’s Full Stack Testing course is specially designed to make students proficient in both manual testing fundamentals and automated testing tools, along with exposure to API testing, performance testing, and DevOps integration. The institute stands out for its experienced trainers, live projects, placement support, and flexible learning options including classroom and online modes.


Whether you are a fresher aiming for a job or a working professional looking to upskill, Quality Thought offers customized learning paths. Its strong industry connections ensure regular placement drives and job interview 

Loops in Java: for, while, do-while

 In Java, loops are used to execute a block of code repeatedly based on a condition. Java provides three main types of loops: for, while, and do-while.


for loop is used when the number of iterations is known. It has three parts: initialization, condition, and increment/decrement.

Example:


java

Copy

Edit

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

    System.out.println(i);  

}  

This loop prints numbers from 1 to 5.


while loop is used when the number of iterations is not known and depends on a condition. The condition is checked before each iteration.

Example:


java

Copy

Edit

int i = 1;  

while(i <= 5) {  

    System.out.println(i);  

    i++;  

}  

This also prints numbers from 1 to 5.


do-while loop is similar to the while loop, but it checks the condition after executing the block, so it runs at least once.

Example:


java

Copy

Edit

int i = 1;  

do {  

    System.out.println(i);  

    i++;  

} while(i <= 5);  

This loop prints numbers from 1 to 5.


These loops are essential for tasks like iterating over arrays, processing user input, and running repetitive calculations. Choosing the right loop depends on the logic and flow of your program.

Lern More

Arrays in Java: Single and Multi-dimensional

Read More

Java Data Types and Variables


Comments

Popular posts from this blog

What is Tosca and what is it used for?

Compute Engine (VMs)

What is Software Testing