Sunday 3 August 2014

How to skip a number from a Loop in Java

Structure of the Problem Requirements 

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. Here is the source code of this problem which help you to understand better.

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
Java Loops





Share it Please
asad

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

0 comments:

Post a Comment