Home Java Java-get-example Java error unreachable statement

Related Tutorials


 
 

Share on Google+Share on Google+

Java error unreachable statement

Advertisement
In this Tutorial we want to describe you a code that help you in understanding a unreachable statement. For this we have a class name' unreachable error', Inside the main method we have a for loop that has a variable integer I.;.

Java error unreachable statement

     

In this Tutorial we want to describe you a code that help you in understanding a unreachable statement. For this we have a class name' unreachable error', Inside the main method  we have a for loop that has a variable integer I.;. The System.out.println is used to display the value of  variable integer i  on command prompt. The continue statement in the code prevent from the normal execution of the code. The only difference  between the continue and break statement is that break statement exits the control of the expression from the loop, but continue statement put the expression in the loop but without executing the code written after the continue statement. This code show you how the statement become unreachable after continue statement.

 

 

 

unreachableerror.java


import java.util.*;

public class unreachableerror {

  public static void main(String arg[]) {
  for (int i = 0; i <= 5; i++)
  {
  System.out.println(i);
  continue;
  System.out.println(i);

  }
  }
}

On the execution of a program, the output on the command prompt is  displayed as
Output

Compiling source file to /home/girish/NetBeansProjects/errors/build/classes
/home/girish/NetBeansProjects/errors/src/
unreachableerror.java:
11: unreachable statement
  System.out.println(i);
error
BUILD FAILED (total time: seconds)

To resolve this error remove continue; from this program

Download code
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 3, 2008

Related Tutorials

Discuss: Java error unreachable statement   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
Guru
September 4, 2011
Solve "Continue"

Dear, You can not write "Continue" keyword in without condition block, It must be write into like "IF" condition block.. Try it.. if(i==3) { continue; }
Ankur Jain
October 25, 2012
Unrechable statements

package com.lara; import java.util.Scanner; public class F { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter Some-Thing"); String s1 = sc.next(); int i = test(s1); System.out.println(i); } static int test(String s1) {int i = 0; try { i = Integer.parseInt(s1); return i; } catch (NumberFormatException ex) { return 0; } /*catch (ArithmeticException ex1) { System.out.println(7); System.out.println(ex1); System.out.println(8); }*/ finally { return 1000; } System.out.println(1); } }
DMCA.com