2011-04-16 235 views
1

請看看這段代碼:while循環變量更新

int page; 
int stop = FALSE; 

while (!stop) { 
    printf("stop0 %i\n", stop); 

    if (physmem[fifo_index % opts.phys_pages] == NULL) { 
     stop = TRUE; 
     page = fifo_index % opts.phys_pages; 
     printf("stop1 %i\n", stop); 

    } else if (physmem[fifo_index % opts.phys_pages]->gc_bit == 0) { 
     physmem[fifo_index % opts.phys_pages]->gc_bit = 1; 
     printf("stop2 %i\n", stop); 

    } else if (physmem[fifo_index % opts.phys_pages]->gc_bit == 1) { 
     stop = TRUE; 
     page = fifo_index % opts.phys_pages; 
     printf("stop3 %i\n", stop); 

    } 
    printf("sto4 %i\n", stop); 

    fifo_index++; 
    printf("stop5 %i\n", stop); 

} 

輸出是:

stop0 0 
stop1 1 
stop4 1 
stop5 1 
stop0 0 '<<< I dont understand this part' 
stop1 1 
stop4 1 
stop5 1 
      '<<<< The code exits here!! In the second loop...whyy??' 
+0

此代碼是否位於某個外部循環? – Adam 2011-04-16 05:25:50

+1

我注意到你沒有真正複製/粘貼輸出,因爲「sto4」在你的代碼中拼寫錯誤,但在你的輸出中沒有。 – Adam 2011-04-16 05:26:21

+1

你怎麼知道它循環了兩次?你有可能兩次調用這個函數嗎? – 2011-04-16 05:27:39

回答

0

你可以把上面的printf聲明while和檢查,如果你是兩次進入循環。

+0

我覺得漂亮stoopid。累:( – moejoe 2011-04-16 06:54:33