UDP client stuck in infinite loop

publicstaticvoid main(String args[])throws Exception

{

BufferedReader inFromUser=new BufferedReader(newInputStreamReader(System.in));

DatagramSocket clientSocket=new DatagramSocket();

InetAddress IPAddress = InetAddress.getLocalHost();

byte[] sendData =newbyte[1024];

byte[] receiveData =newbyte[1024];

String sentence ="";

boolean quit =true;

while(quit ==true);

{

String initiateConntact ="hi there";

sendData= initiateConntact.getBytes();

DatagramPacket sendPacket=new DatagramPacket(sendData, sendData.length, IPAddress, 9876);

clientSocket.send(sendPacket);

DatagramPacket receivePacket=new DatagramPacket(receiveData, receiveData.length);

clientSocket.receive(receivePacket);

String modifiedSentence=new String(receivePacket.getData());

InetAddress getIPFromServer = receivePacket.getAddress();

System.out.println("The server is located at : " + getIPFromServer);

sentence = inFromUser.readLine();

System.out.println("From Server:" + modifiedSentence);

if(sentence.equals("bye"));

{

quit =false;

clientSocket.close();

}

}

}

I am just courious why this pice of code gets stuck in an infinite loop.

(it seems anyway). It doesnt even make it into the while statement. If i replace the while with an if statement, everything works smoothly. Does anyone know what is actually happening here and why?

Thanks for your time.

[2580 byte] By [Kiffena] at [2007-9-29 17:32:57]
# 1
ok..My mistake.while(quit = true)did the trick..
Kiffena at 2007-7-15 16:30:23 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 2
> while(quit == true); <-- remove this ';' character
warnerjaa at 2007-7-15 16:30:23 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 3
> ok..> My mistake.> > while(quit = true)> > did the trick..I hope you meant '==', not '=', and removed the offending ';'
warnerjaa at 2007-7-15 16:30:23 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 4
Hehe.. Its been a long day..Why didnt the java compiler report the ;? or the missing =?Just wondering.Thanks for the help warnerja
Kiffena at 2007-7-15 16:30:23 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 5

> Why didnt the java compiler report the ;? or the

> missing =?

Because they're both syntactically valid.

You might want to code a loop with no body:

while ((ch = readChar()) != 0);

(same as)

while ((ch = readChar()) != 0)

{

// do nothing

}

And you might want to assign a boolean variable and compare it at the same time:

while (flag = callSomeMethod())

(as opposed to)

while ((flag = callSomeMethod()) == true)

Although in both cases I'd write them differently rather than making a statement which has 'side-effects' and makes for slightly less-readable code.

warnerjaa at 2007-7-15 16:30:23 > top of Java-index,Archived Forums,New To Java Technology Archive...