2012-11-28 42 views

回答

6

你差點沒錢了。

y <- i <- 0 
while(y < 10) { 
    i <- i + 1 
    y <- y + 2 
    print(y) 
} 
print(sprintf("The loop repeated %s times.", i)) 
0

嘗試使用遞歸。 例如,您要將限制設置爲執行五次。

 

     function test(int y,int current,int limit){ 
     if (current>limit) return; 
     print (y); 
     test(y+2,current+1,limit); 

} 

調用函數主代碼中:

 

    int start=0; 
    test(start,1,5); 

+1

酷,壽」當然'的整點while'是避免填充迴路或功能與'if'聲明: - )。當終端值未知或函數本身改變時,通常使用遞歸(請參閱任何示例「階乘」遞歸函數)。 –