How to skip a number from a Loop in Java

In this lesson we will learn how to remove a number or iteration from loop execution. we solve this problem in for loop but it could be apply to any types of loop in any programming. To achieve this just put the condition in loop with your number and after this enter the key word Continue.

Source Code


package com.ancodingpoint.www;
import java.util.Scanner;

public class Loops{

 public static void main(String[] args) {
    Scanner input = new Scanner (System.in);
    int a =0;
    for ( int i =0; i<10;i++ )
    {
        if ( i== 5)
        {
            continue;
        }
        System.out.println(i);
    }
}
 }

Output of the Program

Java Programming





Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment