wood burning stoves 2.0*
The moose likes Cattle Drive and the fly likes for()  identifiers question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "for()  identifiers question" Watch "for()  identifiers question" New topic
Author

for() identifiers question

Zkr Ryz
Ranch Hand

Joined: Jan 04, 2001
Posts: 187
I have recived a feed back from queiroz

Saying the next:

<pre>
for( int i = 0, j = 0 ; i < n ; i++, j++ )
{
//body here
}
</pre>

"This is something I prefer to avoid. I like to see each identifier on its own line"

But Im not quite sure to understand what does this means.

Would this be a satisfactory "for" statement construction?

<pre>
for( int i = 0,
j = 0 ;
i < n ;
i++,
j++ )\
{
//body here
}
</pre>


Any suggestion?

Thanks.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
How about two separate if statements?

or a for statement and j stuff inside


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Zkr Ryz
Ranch Hand

Joined: Jan 04, 2001
Posts: 187
Oh Marylin I see you're there, well, I don't really get this one, what's the real problem about having compound identifiers on the same line. This is the first time someone have mention that is a bad coding style.

Well I gues it's for my own good, but I still would like to know why ?

C'ya
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20496
    ∞

It looks like the values are going to be the same. Is there a way to leave one out?
The key is that the for loop is pretty damn ugly in its simplist form.
When you are doing the nitpicking and trying to understand what is going on - or if you are just trying to figure out why your own code works, it sure helps to have clean, readable, obvious code.
If you start getting fancy, and then work in lots of little fancy tricks, your code becomes really hard to read.
For the cattle drive, Readability is more important than anything else.


permaculture Wood Burning Stoves 2.0 - 4-DVD set
Zkr Ryz
Ranch Hand

Joined: Jan 04, 2001
Posts: 187
Paul:

Well, actually the 'j' is evaluated inside the "for", and reach another value.

Im understandig the reason why to keep code on its simplier way is better.( I remenber the day I have to read someone else code , grrrrr!!!)

So, I suppose that in cattle drive it won't be accepted a one line statement like this:

<pre>
Sistem.out.println( a > b ? " a > b " : "a<=b"); <br /> </pre><br /> And I should use this other instead:<br /> <br /> <pre><br /> if( a > b )
{
System.out.println("a > b");
}
else
{
System.out.println("a <= b");
}
</pre>
More lines, but everyone can understand it . . . .

Ciao
 
 
subject: for() identifiers question
 
Similar Threads
Turn Based Strategy Games
A Simple Control Flow Question
switch and labeled break
Whining: Font Size
Find 127th twin-prime pair?