Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-20-2007, 04:45 PM
Member
 
Join Date: Jul 2007
Posts: 41
fred is on a distinguished road
help with basic example
I have this code:
Code:
for(int i=0; i<100; i++) { str = br.readLine(); System.out.println("String"+ i + str); if(str.equals("stop")) break; }
If I remove the System.out.println, it is going for an infinite loop.
why?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-20-2007, 06:45 PM
Senior Member
 
Join Date: Jul 2007
Posts: 130
cruxblack will become famous soon enough
fred, i suggest if ur going to ask bout some code later, try to put the full code in the post

Ur post, since it's only half the code, lost some of the important information involving the program, so it's hard to analyze what's wrong with it actually

The missing points
- we don't know what br are
just using assumptions, from the name i presume it may be a BufferedReader instance
- we also don't know what str are or what it may consists
another assumptions, it should be a String right?

So, based on a rough assumption, in which im not as good of a Sherlock Holmes in assuming things, so if im wrong please correct me
The code should be like this or some sort
Code:
import java.io.*; public class Fred { public static void main(String[] args)throws IOException { BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); String str; for(int i=0; i<100; i++) { str = br.readLine(); System.out.println("String"+ i + str); if(str.equals("stop")) break; } } }
If this is the code, which i doubt it is, i already tried deleting the System.out.print inside the for loop, it work just okay, no infinite loop

Besides, an infinite loop in a for loop with that kinda parameter is really rare, might be possible if u insert a decrement operation for i (i--) inside the brackets of the loop, which u didn't
But usually, infinite loop doesnt occur in for loop, while loop maybe, but not for loop

This is the best i can do to help, i suggest u post the full source code
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
basic java help adred New To Java 0 03-08-2008 01:36 PM
Basic Program Please Help!! VinceGuad New To Java 3 02-01-2008 04:35 PM
Basic question about EJB javaplus Enterprise JavaBeans 0 12-02-2007 11:00 PM
Basic Graphic jkswebsite Java 2D 6 11-26-2007 03:19 AM
Basic Java help, AIM? jkswebsite New To Java 0 11-24-2007 10:10 PM


All times are GMT +3. The time now is 04:46 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org