It's not a secret anymore!
The moose likes Cattle Drive and the fly likes Query on 4b (Say) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Query on 4b (Say) "unrolling loops" nitpick" Watch "Query on 4b (Say) "unrolling loops" nitpick" New topic

Query on 4b (Say) "unrolling loops" nitpick

Rian Nolan

Joined: Jun 21, 2006
Posts: 9
I'm a bit befuddled in 4b(Say) at the moment.
I have it "working" in the broadest possible sense, but I'm obviously overcomplicating matters somewhat, as one of the nitpicks was:
You are putting a whole lot of effort into setting things up so you can use a loop... 3 times. 4 at the most.
I'd like you to "unroll" the loop, hard code each instance, and we'll take it from there.

...and I'm not not quite sure how to "unroll" a loop (or loops)
Should I go from this:

to (something like) this:

Any advice on unrolling loops?
Should I stop rolling my own?
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1789

I just want to say that I don't know the answer... and I hate Say b.

And.... if you're not looping, then why the heck does 'i' make a difference anyways... can't you just do the stuff without looping it?

When you do things right, people won't be sure you've done anything at all.
Katrina Owen

Joined: Nov 03, 2006
Posts: 1367
What Janeice said (no, not the censored bit!)

you don't need i, just do something like this.

If you get stuck, ping your nitpicker for hints, or ask obliquely here on the forum!
Gary Ba
Ranch Hand

Joined: Oct 23, 2009
Posts: 161

random reply to your quesetion...

I too had a difficulty with Say b so your not the only one.


star chaser..
Rian Nolan

Joined: Jun 21, 2006
Posts: 9
Found these threads which managed to cover off all of my concerns about unrolling loops and not using ternary operators:
Nice to know that I'm not completely off the beaten track!
Math, Ternaries, Passing and Returning
Say 4b - completely stumped attempt#2 with ifs everywhere, and nested loops unrolled is on its way...
Katrina Owen

Joined: Nov 03, 2006
Posts: 1367
Rian, I promise it's worth it. I know it feels just awful to hard code it like that... but there are efficiencies and beautiful things on the other side that you just cannot get to while you have that loop in place. Promise.
I agree. Here's the link:
subject: Query on 4b (Say) "unrolling loops" nitpick
jQuery in Action, 3rd edition