473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

break statement

281 100+
Good Day all!...Could I ask one question about break please...
Why I am getting nothing when I put this break? at least it prints something
if it's true...please refer my codes below:
Expand|Select|Wrap|Line Numbers
  1. if(name2.equals(name1)) {
  2.        if(add2.equals(add1))  {
  3.           if(!(val2.equals(val1)))              {                                                                                                 
  4.    printWriter.println(fileno + " : " + name2 );
  5.     break;
  6.                      }                    
  7.                 } 
  8.  
  9.            }                     
It works fine if I take out the break statement. But then it will exercise all lines in my inputfile. What I want is, after I got the first output then it will stop checking the next line....please feel free to reply me. thank you.
May 10 '07 #1
9 2831
r035198x
13,262 8TB
Good Day all!...Could I ask one question about break please...
Why I am getting nothing when I put this break? at least it prints something
if it's true...please refer my codes below:
Expand|Select|Wrap|Line Numbers
  1. if(name2.equals(name1)) {
  2. if(add2.equals(add1)) {
  3. if(!(val2.equals(val1))) { 
  4. printWriter.println(fileno + " : " + name2 );
  5. break;
  6.  
It works fine if I take out the break statement. But then it will exercise all lines in my inputfile. What I want is, after I got the first output then it will stop checking the next line....please feel free to reply me. thank you.
Post code for the whole loop that you are trying to break from.
May 10 '07 #2
JosAH
11,448 Expert 8TB
break statements can only occur in loop bodies where it stops the loop immediately
or in case clauses in which case the break prevents "fall-through" and breaks
out of the entire switch statement. Your code snippet doesn't show loops nor
switch statements ...

kind regards,

Jos
May 10 '07 #3
shana07
281 100+
break statements can only occur in loop bodies where it stops the loop immediately
or in case clauses in which case the break prevents "fall-through" and breaks
out of the entire switch statement. Your code snippet doesn't show loops nor
switch statements ...

kind regards,

Jos
Thank you very much..Now I know about the break..I thought it can stop from execute/read next line (FileReader) by putting the 'break' statement.
so there's no way to put break after 'if' syntax..

One more question about readLine() please...
How am I going to get the last line (EOF)- value to be printed?
I have this code:

Expand|Select|Wrap|Line Numbers
  1. line1 = in1.readLine();
  2. line2 = in2.readLine();
  3.  
  4. while ((line1 ! = null) && (line2 != null)) {
  5.  ............ 
  6. ....
  7. line1 = in1.readLine();
  8. line2 = in2.readLine();
  9. }
  10.  
  11. //then I need to print out the last line for both files? 
Kindly please help me what's the syntax for printing the lastline value?
Thank you
May 11 '07 #4
dmjpro
2,476 2GB
try this code ......

while((line1 = in1.readLine()) != null && (line2 = in2.readLine()) != null)
{
//prints two strings here.
}

if(line1 != null)
{
//prints the line1
while((line1 = in1.readLine()) != null) //prints the line1
}
else if(line2 != null) //prints the line2
{
//prints the line2
while((line2 = in2.readLine()) != null) //prints the line2
}
i think u got my logic.
have a good day.

kind regards.
dmjpro.
May 11 '07 #5
shana07
281 100+
try this code ......



i think u got my logic.
have a good day.

kind regards.
dmjpro.
sorry friend, I don't really get you...anyway I have tried to follow your code - but it doesn't print the last line value still...thank you.
May 11 '07 #6
r035198x
13,262 8TB
Thank you very much..Now I know about the break..I thought it can stop from execute/read next line (FileReader) by putting the 'break' statement.
so there's no way to put break after 'if' syntax..

One more question about readLine() please...
How am I going to get the last line (EOF)- value to be printed?
I have this code:

Expand|Select|Wrap|Line Numbers
  1. line1 = in1.readLine();
  2. line2 = in2.readLine();
  3.  
  4. while ((line1 ! = null) && (line2 != null)) {
  5. ............ 
  6. ....
  7. line1 = in1.readLine();
  8. line2 = in2.readLine();
  9. }
  10.  
  11. //then I need to print out the last line for both files? 
Kindly please help me what's the syntax for printing the lastline value?
Thank you
Expand|Select|Wrap|Line Numbers
  1.  String lastLine = ""; 
  2. while(line != null) {
  3.  
  4. line = input.readLine();
  5. if(line != null) { 
  6.      lastLine = line;
  7. }
  8. }
  9.  
  10. System.out.println(lastLine);
  11.  
May 11 '07 #7
dmjpro
2,476 2GB
hello shana07

did u understand my // line??????

do one more thing if u can plz post ur code what u write with the help of me....
May 11 '07 #8
AdrianH
1,251 Expert 1GB
My 2 cents: Don't use break/continue to manover your way around loops. Bad form old boy.

Unless you have some profiling proof that says that you should use it, don't. It makes for harder to read and verify the code.


Adrian
May 11 '07 #9
dmjpro
2,476 2GB
good idea suggested by AdrianH.

if there is no way then u should use it ... otherwise not.
May 12 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jay | last post by:
G'day all This registration form checks for the submit button then displays the next form from the include statement. But before it displays the next form it will check to make sure the user...
5
by: Ann | last post by:
I have trouble sometimes figuring out where break and continue go to. Is there some easy way to figure it out, or a tool? TIA Ann
25
by: chunhui_true | last post by:
In <<expert c>>I know the break in if wich is scoped in switch is break the switch,like: switch c case 1: if(b){ break; } ...... But like this: while(a){
55
by: Ennixo | last post by:
hi, do you know where i can find some ebooks or websites talking about C# optimisation ? for exemple, i just learned that ++i is faster than i++. i would like to know more about the things...
1
by: Neo | last post by:
I am in dire need of a break statement in VB.NET language. I have several pieces of code that would have much cleaner look and much less deeper if/else/endif nests IF VB.NET HAS A BREAK STATEMENT...
6
by: David | last post by:
I know that by some reasons... the use of "break;" in java language is not correct, is there any similar problems with c#????
26
by: Alexander Korsunsky | last post by:
Hi! I have some code that looks similar to this: -------------------------------------------- char array = "abcdefghij"; for (int i = 0; i < 10; i++) {
22
by: Cogito | last post by:
For the first time, I'm attempting to write a small Javascript program using one on the online reference sites. I need some confirmation as to the behaviour of the break statement. In the...
26
by: a.mil | last post by:
I am programming for code-speed, not for ansi or other nice-guy stuff and I encountered the following problem: When I have a for loop like this: b=b0; for (a=0,i=0;i<100;i++,b--) { if (b%i)...
3
by: Yansky | last post by:
Hi, I've looked through the tutorial on w3cschools.com, but I'm still uncertain as to the difference between using break and using return. If I have a simple "for" loop that I want to stop if a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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...
0
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
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
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,...

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.