
-----------------------------------
ProgrammingFun
Sat Jan 08, 2011 1:09 pm

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?


            checkBoard

-----------------------------------
Tony
Sat Jan 08, 2011 1:15 pm

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.

-----------------------------------
Insectoid
Sat Jan 08, 2011 1:17 pm

RE:Loop Fail
-----------------------------------
A nested for loop should do the trick.
[code]
for x_ : 0-2 {
    for y : 0-2 {
        checkerBoard[x_][y] = gameBoard[x+y-1][x+x_-1]
    }
}
[/code]

-----------------------------------
ProgrammingFun
Sat Jan 08, 2011 2:23 pm

RE:Loop Fail
-----------------------------------
Thanks for the help. I used the following method:

for (int a = 0; a < 3; a++)
{
	for (int b = 0; b < 3; b++)
	{
		checkBoard

-----------------------------------
ProgrammingFun
Sat Jan 08, 2011 5:02 pm

RE:Loop Fail
-----------------------------------
An unrelated question:

If nowin is a boolean will:

if (nowin) mean the same thing as if (nowin == true)
if (!nowin) mean the same thing as if (nowin == false)

Thanks for the help!

-----------------------------------
2goto1
Sat Jan 08, 2011 5:24 pm

RE:Loop Fail
-----------------------------------
Yes and yes. Try spitting out each to your console to confirm

-----------------------------------
ProgrammingFun
Sat Jan 08, 2011 5:52 pm

Re: RE:Loop Fail
-----------------------------------
Yes and yes. Try spitting out each to your console to confirmOK, thanks for the help...

-----------------------------------
copthesaint
Mon Jan 10, 2011 3:31 am

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.


Sooo...
Does this work for yea then :P SAVES  1 LINE!!! :) *not counting brackets*

for (int i = 0; i < 9; i++){
heckBoard

Lol I dont want to know how complex it would be to minipulate the values for a 3 dimensional array doing this... lol

-----------------------------------
DemonWasp
Mon Jan 10, 2011 10:45 am

RE:Loop Fail
-----------------------------------
Incidentally, always choose readability over number of lines of code. In fact, choose readability over anything except a real requirement.

-----------------------------------
Tony
Mon Jan 10, 2011 11:42 am

Re: Loop Fail
-----------------------------------
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/

-----------------------------------
copthesaint
Tue Jan 11, 2011 10:28 pm

RE:Loop Fail
-----------------------------------
Lol, that is really great tony... :D, Also DemonWasp, whats the fun in readability :P jk
