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

Basic and Advanced Loops in Java

The document provides examples of basic and advanced loops in Java, including for loops, while loops, do-while loops, and enhanced for-each loops. It also mentions infinite loops and demonstrates nested loops. Each loop type is illustrated with code snippets showing their functionality.

Uploaded by

vineeth
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)
28 views

Basic and Advanced Loops in Java

The document provides examples of basic and advanced loops in Java, including for loops, while loops, do-while loops, and enhanced for-each loops. It also mentions infinite loops and demonstrates nested loops. Each loop type is illustrated with code snippets showing their functionality.

Uploaded by

vineeth
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

* Basic and Advanced Loops in Java

public class LoopExamples {

public static void main(String[] args) {

// 1. Basic Loops

// a) For Loop

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

System.out.println("For Loop: " + i);

// b) While Loop

int j = 0;

while (j < 5) {

System.out.println("While Loop: " + j);

j++;

// c) Do-While Loop

int k = 0;

do {

System.out.println("Do-While Loop: " + k);

k++;

} while (k < 5);

// 2. Advanced Loops

// a) Enhanced For Loop (For-Each Loop)

int[] numbers = {1, 2, 3, 4, 5};

for (int num : numbers) {

System.out.println("Enhanced For Loop: " + num);


}

// b) Infinite Loop (Use with caution)

/*

while (true) {

System.out.println("Infinite Loop");

*/

// c) Nested Loops

for (int a = 1; a <= 3; a++) {

for (int b = 1; b <= 3; b++) {

System.out.println("Nested Loop: " + a + "," + b);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy