Forums Register Login

for ( ; ;)

+Pie Number of slices to send: Send
When we write the for-loop header as follows, what does it mean?

for(; ;)
{

}


Thanks

[edited to disable smilies]
[ May 22, 2008: Message edited by: Jeanne Boyarsky ]
+Pie Number of slices to send: Send
Abder,
That loop runs forever since there is no end loop condition.

Normally, it looks like this:

The first piece initializes, the second piece checks if we are done and the third piece moves us closer to the end.
+Pie Number of slices to send: Send
Thank you very much.
[ May 22, 2008: Message edited by: Abder-Rahman Ali ]
+Pie Number of slices to send: Send
A bit more elaborate:

A for loop header has three parts: the initializer, the condition and the increment. The loop will first execute the initializer part, and then while the condition returns true it will execute the loop body, then the increment.

In this example there is no initializer, no increment and no condition. If omitted, the condition yields true, so the loop is a synonym for the following:
+Pie Number of slices to send: Send
 

Originally posted by Rob Prime:
A bit more elaborate:

A for loop header has three parts: the initializer, the condition and the increment. ...



Not Always


Jeanne Boyarsky :
The first piece initializes, the second piece checks if we are done and the third piece moves us closer to the end.


[ May 23, 2008: Message edited by: Vishal Pandya ]
+Pie Number of slices to send: Send
But it is still mostly called the increment statement. Wikipedia calls it the "counting expression".
You're right that it doesn't have to be an increment on integers, or even needs to be present.
+Pie Number of slices to send: Send
 

Originally posted by Rob Prime:
But it is still mostly called the increment statement. Wikipedia calls it the "counting expression".
You're right that it doesn't have to be an increment on integers, or even needs to be present.



The Java Language Spec calls it the "ForUpdate" part, which isn't even a word (14.14.1)! I agree -- I think most people call it the "increment."
+Pie Number of slices to send: Send
I agree too. I've heard it called the increment. I choose my words more carefully so as not to imply it couldn't go backwards.
+Pie Number of slices to send: Send
I still remember it from when I was programming in C -- the three components of the "for" loop, in C, were the initializer, condition, and reinitializer.

Henry
+Pie Number of slices to send: Send
Both Guy Steele and K&R call them "expression1", "expression2" and "expression3" !
+Pie Number of slices to send: Send
Well that certainly is self-explanatory.
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1120 times.
Similar Threads
I am Looking for a SCJP 6 voucher
AJAX on IE
SCJP6 book page 298 errata
Insert the current date
NullPointerException in PreparedStatement...
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:55:23.