This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

For loop

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?

Parents
  • "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 )
    

Reply
  • "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 )
    

Children