Skip to main content

Timeline for Too many loops in Drawing App

Current License: CC BY-SA 2.5

9 events
when toggle format what by license comment
Jan 21, 2011 at 15:36 comment added Felix Dombek @Carlos right -- what we need is a formula to spit out a number for any n. I can't think of the right one just now, but it probably has do something with log2
Jan 21, 2011 at 14:36 comment added Carlos Muñoz Mmmm let's see. How would you implement this mathematical function: f(x) = 3x . This way: F(int x) { return 3 * x } Or this way: F(int x) { if ( x == 1 ) return 3; if (x == 2) return 6; if (x == 3) return 9; ..... } or maybe this way: F(int x) { switch (x) { case 1: return 3; case 2: return 6; case 3 return 9; ..... } }
Jan 21, 2011 at 9:19 comment added Aim Kai I'm not sure if replacing the else ifs with this is any more readable and if the code would would perform better..
Jan 20, 2011 at 23:59 comment added Carlos Muñoz Don't forget The question says it should be done not just for 6 but for n iterations. There's no such thing as a dynamic-n-cases-switch. But I do agree that portion of code should be in it own method
Jan 20, 2011 at 22:03 comment added Felix Dombek There seem to be some prejudices towards using a control statement exactly for what it was made. I embrace brevity, but if this is in its own method it will be readable again, and if performance makes a difference, I would strongly prefer the switch statement
Jan 20, 2011 at 2:18 comment added Adam Lear @Felix: But a switch statement wouldn't really make the code shorter.
Jan 20, 2011 at 0:42 comment added Felix Dombek alternatively, a switch statement would help and introduce absolutely no overhead (in fact, it's faster than repeated if/else operations)
Jan 19, 2011 at 22:51 history edited Carlos Muñoz CC BY-SA 2.5
added 1 characters in body
Jan 19, 2011 at 22:34 history answered Carlos Muñoz CC BY-SA 2.5