The Artima Developer Community
Sponsored Link

Java Answers Forum
why doesnt it loop ? ? ?

2 replies on 1 page. Most recent reply: Nov 7, 2003 12:01 PM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
stelios

Posts: 1
Nickname: stevoo
Registered: Nov, 2003

why doesnt it loop ? ? ? Posted: Nov 7, 2003 6:04 AM
Reply to this message Reply
Advertisement
IntDLLNode tmp = head;IntDLLNode tmp1 = head ;IntDLLNode tmp2 = head ;
for ( ; tmp != null ; tmp = tmp.next, tmp1 = tmp1.next,tmp2 = tmp2.next)
if ( tmp == null )
return ("No passenger on the flight " );
else return ("Passenger : " +tmp.info + " phone : "+ tmp1.info1 + " \n " ) ;

return ("NO flight " );

this is my code guys ive been wondering ? isnt it correct ? why doesnt it loop and simply returns me the first input i put ? hoe will i show the rest ?


s

Posts: 23
Nickname: codemonkey
Registered: Nov, 2003

Re: why doesnt it loop ? ? ? Posted: Nov 7, 2003 6:49 AM
Reply to this message Reply
why are you checking temp for null when
it shouldnt go into the loop if it is????
but i would say its broke because you are
using a RETURN when you hit the first one!!
Do you just want to print it out or should you
be stuffing it into a Vector or something?
i mean start off by knowing that multiple returns
in a method are evil !

IntDLLNode tmp = head;
IntDLLNode tmp1 = head ;
IntDLLNode tmp2 = head ;
for ( ; tmp != null ; tmp = tmp.next,
tmp1 = tmp1.next,tmp2 = tmp2.next)// what are you doing with tmp2??
if ( tmp == null )///dont need this line i think.
String returnValue;
returnVal = "Passenger : " +tmp.info + " phone : "+tmp1.info1 + " \n ";
if(//code to check for no flight){
returnValue="NO flight ";

return returnValue; //aaahhhh one return stmnt !
}
//return ("No passenger on the flight " );
//else return ("Passenger : " +tmp.info + " phone : "+ //tmp1.info1 + " \n " ) ;

return ("NO flight " );

thats the best i can do with the limited info youve given ..
good luck

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: why doesnt it loop ? ? ? Posted: Nov 7, 2003 12:01 PM
Reply to this message Reply
It might help a lot if you simply clean up the code; use meaningful variable names, don't try to overstuff the for clause. Don't try to be tricky or clever. Try to make the code clear and explicit and the bugs will magically fall away.

Flat View: This topic has 2 replies on 1 page
Topic: Java dates - urgent Previous Topic   Next Topic Topic: Server Socket IP

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use