Computer Science Canada Loop Fail |
Author: | ProgrammingFun [ Sat Jan 08, 2011 1:09 pm ] | ||
Post subject: | Loop Fail | ||
I can't think of any way to do this in a more efficient way (perhaps using for-loops)...so I posted to ask, is there a better way to do this?
|
Author: | Tony [ Sat Jan 08, 2011 1:15 pm ] |
Post subject: | RE:Loop Fail |
If by "more efficient" you mean "less lines of code", then yes. Two for-loops and a single assignment statement. Edit: strictly speaking, you can do this with a single for-loop, at the cost of readability. |
Author: | Insectoid [ Sat Jan 08, 2011 1:17 pm ] | ||
Post subject: | RE:Loop Fail | ||
A nested for loop should do the trick.
|
Author: | ProgrammingFun [ Sat Jan 08, 2011 2:23 pm ] | ||
Post subject: | RE:Loop Fail | ||
Thanks for the help. I used the following method:
|
Author: | ProgrammingFun [ Sat Jan 08, 2011 5:02 pm ] |
Post subject: | RE:Loop Fail |
An unrelated question: If nowin is a boolean will:
Thanks for the help! |
Author: | 2goto1 [ Sat Jan 08, 2011 5:24 pm ] |
Post subject: | RE:Loop Fail |
Yes and yes. Try spitting out each to your console to confirm |
Author: | ProgrammingFun [ Sat Jan 08, 2011 5:52 pm ] |
Post subject: | Re: RE:Loop Fail |
2goto1 @ Sat Jan 08, 2011 5:24 pm wrote: Yes and yes. Try spitting out each to your console to confirm OK, thanks for the help... |
Author: | copthesaint [ Mon Jan 10, 2011 3:31 am ] | ||
Post subject: | Re: Loop Fail | ||
Tony wrote: If by "more efficient" you mean "less lines of code", then yes. Two for-loops and a single assignment statement. Edit: strictly speaking, you can do this with a single for-loop, at the cost of readability. Sooo... Does this work for yea then ![]() ![]()
Lol I dont want to know how complex it would be to minipulate the values for a 3 dimensional array doing this... lol |
Author: | DemonWasp [ Mon Jan 10, 2011 10:45 am ] |
Post subject: | RE:Loop Fail |
Incidentally, always choose readability over number of lines of code. In fact, choose readability over anything except a real requirement. |
Author: | Tony [ Mon Jan 10, 2011 11:42 am ] |
Post subject: | Re: Loop Fail |
copthesaint @ Mon Jan 10, 2011 3:31 am wrote: Lol I dont want to know how complex it would be to minipulate the values for a 3 dimensional array doing this... lol
You weren't around for this, but things very quickly get out of hand... http://compsci.ca/blog/your-computer-science-isu-in-20-lines/ |
Author: | copthesaint [ Tue Jan 11, 2011 10:28 pm ] |
Post subject: | RE:Loop Fail |
Lol, that is really great tony... ![]() ![]() |