What's wrong with my Do While Condition?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mingke
    New Member
    • Dec 2008
    • 16

    What's wrong with my Do While Condition?

    If for example I have four arrays (with different value), and I have another array which is the result of calculation between these four arrays. Then, I can sort the final array to ascending order and I want to search from the four arrays that can result the sorted final array...

    I used do while loop but I guess something wrong with it because it keep resulting 0.

    Here's my a part of code which has problem:
    Code:
     
    for (i=0; i<size2; i++){          
          for (k = 0; k < point3[i]; k++){       
               for (a=0;a<b[i][k];a++){          
                    for (l=0;l<b[i][k];l++){
                         do{
                    
                   gradient [i][k][a]= fabs((S[i][k][j]-Cy[i][k])/(R[i][k][j]-Cx[i][k]))-teta[i][k][a]; 
    //teta[i][k][a] =  fabs((S[i][k][a]-Cy[i][k])/(R[i][k][a]-Cx[i][k])),but in the statement above teta[i][k][a] has already sorted
    
                        X[i][k][a]=R[i][k][l];    
                        Y[i][k][a]=S[i][k][l]; 
                     }
                   while (gradient[i][k][a]==0);  
                   
                   }
                  printf ("[%d][%d][%d]=%f\n",i,k,a,X[i][k][a]);   
                    
               }
          }
        }
    Could you help me spot the error, please?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Have you tried stepping through this with your debugger?

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      I may not be looking closely enough, but it looks to me like the same value will be assigned to gradient[][][] each time through the loop. Nothing changes. I would expect you to either exit from the loop after a single pass or get stuck there in an infinite loop.

      Comment

      Working...