473,586 Members | 2,683 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\m eme\test.java:2 4: unreachable
statement
System.out.prin tln(t);
^
1 error
=============== ======
public class test{
public static void main(String arg[])
{
for (int t=0;t<5;t++)
{
System.out.prin tln(t);
continue;
System.out.prin tln(t); // the problem with this statement (this
unrechable) why

}
}
}

Jul 17 '05 #1
3 4010
> for (int t=0;t<5;t++)
{
System.out.prin tln(t);
continue;
System.out.prin tln(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****@btinter net.com_> wrote in message
news:Qu******** *************@n ews-text.cableinet. net...
for (int t=0;t<5;t++)
{
System.out.prin tln(t);
continue;
System.out.prin tln(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
2162
by: raizor | last post by:
This email address is unreachable. It has been closed.
4
1637
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 fib(x): .... if (x == 1): .... return 1
1
1734
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* to be front-ended on multiple databases as well as rendered in multiple browser types. That being said, is there a pre-constructed class out there...
4
2825
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 this ? C++ exceptions are enabled ( /EHsc ). Thanks. SS
2
1982
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
27528
by: dfetrow410 | last post by:
Can I do this in an if statement? public string getClass() { counta = counta + 1; if (counta < 2 ) {
4
6970
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
1578
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 work " .mysql_insert_id(); and not any other php or mysql error to tell me if anything is wrong the insert statment. To top it up, I have an echo...
1
2503
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 possibly be done after the return statement hence the break statement will not and can ever be reached? switch (suffix) { case 1: return...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8216
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2345
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 we have to send another system
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.