Break And Continue In Java

package com.company;

import java.util.Scanner;


public class tuts {

    public static void main(String[] args) {

//      for (int i=1; i<=10;i++){

//            System.out.println(i);

//        }

//        Quick Quiz

//        int a = 2;

//        for (int o = 0; o<=30; o++){

//            System.out.println(o*2+1);

//        }


//        Quick Quiz

//        for (int i = 100; i>0; i--){

//            System.out.println(i);

//        }

//            Break will end the whole loop and ends/exits the loop.

//            Continue means to finish the iteration for the particular value and continue like if continue is for 2 so

//            2 will not get printed and the program will print 3.

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

            System.out.println(i);

            if (i==2){

                System.out.println("Ending The loop");

                break;


            }

        }


    }

}

 

Comments

Popular posts from this blog

Creating a Thread by Extending Thread class

Constructors from Thread class in Java