473,508 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unreachable statment??

I am trying to understand why "continue" keyword is used for, therefore I
compiled this code but I got this error message.. why
====================
C:\Program Files\JCreator LE\MyProjects\meme\test.java:24: unreachable
statement
System.out.println(t);
^
1 error
=====================
public class test{
public static void main(String arg[])
{
for (int t=0;t<5;t++)
{
System.out.println(t);
continue;
System.out.println(t); // the problem with this statement (this
unrechable) why

}
}
}

Jul 17 '05 #1
3 3999
> for (int t=0;t<5;t++)
{
System.out.println(t);
continue;
System.out.println(t); // the problem with this statement (this
unrechable) why

}


'continue' means skip the rest of the code in the loop and go to the
next iteration, hence the second println(t) always gets skipped and is
deamed 'unreacheable'. If you change 'continue;' to 'if (true)
continue;' however, it will work (that is, you won't get an error).

SteveE

Jul 17 '05 #2
is skipping a part of code is ERROR??
why the error message.. what is the use of continue??
so much confusing!!!!!

"SteveE" <ea****@btinternet.com_> wrote in message
news:Qu*********************@news-text.cableinet.net...
for (int t=0;t<5;t++)
{
System.out.println(t);
continue;
System.out.println(t); // the problem with this statement (this
unrechable) why

}


'continue' means skip the rest of the code in the loop and go to the
next iteration, hence the second println(t) always gets skipped and is
deamed 'unreacheable'. If you change 'continue;' to 'if (true)
continue;' however, it will work (that is, you won't get an error).

SteveE

Jul 17 '05 #3
leza wrote:
is skipping a part of code is ERROR??
why the error message.. what is the use of continue??
so much confusing!!!!!


It's a 'clever' feature of the compiler. If it can determine for sure
that a piece of code can never be executed, it will flag it up as such.
You can fix the code if it's a bug, or remove it if it's redundant. It
can be quite handy in complicated code with lots of throws or try/catch
blocks, etc.
Think of continue as a 'goto' end of loop (or a label for nested loops).

Explanation and examples are here:
http://java.sun.com/docs/books/tutor....html#continue

SteveE

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2152
by: raizor | last post by:
This email address is unreachable. It has been closed.
4
1634
by: Tom Anderson | last post by:
Evening all, Here's a brief chat with the interpretator: Python 2.4.1 (#2, Mar 31 2005, 00:05:10) on darwin Type "help", "copyright", "credits" or "license" for more information. >>> def...
1
1726
by: Me, Myself, and I | last post by:
First off, i apologize if my terminology is off... I am currently in a project that is basically a front-end to a database. In coding this, I am taking into account that it has the *potential*...
4
2810
by: SteadySteps | last post by:
Hi I migrated a project which compiles correctly on VC 6.0 to VS 2002. However now all I get several warning that all the statements within catch blocks are "unreachable code". How can I correct...
2
1973
by: Hovik Melikyan | last post by:
This code produces a 'unreachable code' warning at line 16 (throw new X ...) with no visible reason: #include <string> class X { std::string msg;
6
27516
by: dfetrow410 | last post by:
Can I do this in an if statement? public string getClass() { counta = counta + 1; if (counta < 2 ) {
4
6963
by: Gernot Frisch | last post by:
I get informed that parts of my code cannot be reached. Did I do something wrong? try { if (login(progstring) > 0) { return 1; // OK } }
1
1574
by: zeebiggie | last post by:
Good morning I have a form with the controls in the insert statment below. table1 has an Auto increment primary key hence is omitted in the insert statment and form. Am getting the error It didnt...
1
2498
by: HillBilly | last post by:
What does that error mean and why would each break statement be marked as unreachable? It implies the return will --always-- return some --thing-- if even null and no further processing can...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7405
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
435
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.