We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
can i use the for loop like this in accessing the 2-d array.
for(u=0;u<=4;u++) { for(v=v1;;) { arr[u][v] += 1; } }
bcos in the second for loop i want to do the increment in some other function.
but the c51 shows an endless loop on executing the second for loop.
can i use only one for loop and no for loop for v since this v i want to increment in some other function?
Thank you.
Since i made mistake in some other place it had affected the for loop.
Thats y i also confused.
Anyway thank you for ur message.
"can i do the increment of the 'y' of arr[x][y] in another function?"
Of course you can!
I think you need to go back to your 'C' textbook, and thoroughly read the description of the 'for' loop, and precisely what the 3 expressions in the 'for' clause actually do...
for( w=0; x<y; z++ ) { : : }
is equivalent to
for( w=0; x<y; ) { : : z++; }
can i do the increment of the 'y' of arr[x][y] in another function?
so that only one for loop is executing for 'x' not for 'y'.
i think u can see the 2D array i have written.
The column increment i want to do separate function not inside the row for loop.
"c51 shows an endless loop on executing the second for loop"
for(v=v1;;)
Of course it does - because it is an endless loop! You haven't specified any exit condition!
You need to add an exit condition - either in the 'for' clause, or a break somewhere in the body of the loop.
Note that the 3 expressions within a 'for' clause don't all have to use the same variable; eg,
for( w=0; x<y; ++z )