Hello,
Should the variable used in a for loop be declared before use?
In the code example I get the error
Error: 'x' not found (line 27 file:Game_of_Life.4dg)
func countNeighbours(var row, var col)
var count:=0;
//var x,y; <==== declare yes or no
for(x:=-1; x <=1; x++) <===== gives no an error
for(y:=-1; y <= 1; y++)
// see for example "BIGARRAY"
if ((board+Index(row+x,col+y) == 1) && (x != 0 || y != 0))
count++;
endif
next
next
return(count);
endfunc
In this function I don't get an error!!!
func drawBoard()
for (row := 0; row < (rows - 2); row++)
for (col := 0; col < (cols - 2); col++)
if board[Index(row + 1,col + 1)]
myGLCD.fillRect(offset_x+col * blockSize, offset_y+row * blockSize, offset_x+(col * blockSize) + blockSize, offset_y+(row * blockSize) + blockSize);
endif
next
next
endfunc
What do I wrong?
Cheers,
Jan
Should the variable used in a for loop be declared before use?
In the code example I get the error
Error: 'x' not found (line 27 file:Game_of_Life.4dg)
func countNeighbours(var row, var col)
var count:=0;
//var x,y; <==== declare yes or no
for(x:=-1; x <=1; x++) <===== gives no an error
for(y:=-1; y <= 1; y++)
// see for example "BIGARRAY"
if ((board+Index(row+x,col+y) == 1) && (x != 0 || y != 0))
count++;
endif
next
next
return(count);
endfunc
In this function I don't get an error!!!
func drawBoard()
for (row := 0; row < (rows - 2); row++)
for (col := 0; col < (cols - 2); col++)
if board[Index(row + 1,col + 1)]
myGLCD.fillRect(offset_x+col * blockSize, offset_y+row * blockSize, offset_x+(col * blockSize) + blockSize, offset_y+(row * blockSize) + blockSize);
endif
next
next
endfunc
What do I wrong?
Cheers,
Jan
Comment