Loops in Java [While Loop, Do While Loop & For Loop]

 


Example of All Loops in Java

1. While Loops
2. Do While Loops
3. For Loops

package com.xdroiddev.calculator;

public class Main {

    public static void main(String[] args) {
	// todo: Loops

        //While Loops

        int i = 0;

        while (i<50){
            System.out.println(i);
            i++; 
        }

        // Do While

        int v = 0;
        do {
            System.out.println(v);
            v++;
        }
        while (v<10);

        // For Loop

        for (int x = 0; x<=30; x++ ){
            System.out.println(x);
        }
    }
}

Post a Comment

0 Comments