2015-09-14 94 views

回答

1

我很驚訝,有人正在開始學習的ActionScript(假設你使用它的閃存),當地球的其他部分朝着HTML5的移動,但是,每一個自己:-)

你想要的算法對於那個順序相對簡單,並且應該很容易轉換成任何程序語言:

for limit = 5 to 1 inclusive, stepping by -1: 
    for number = 1 to limit inclusive, stepping by 1: 
     output number 
    output newline 

基本上就是這樣。根據我(非常)有限接觸AS3,這將出來,就像這樣:

for (var lim:Number = 5; lim > 0, lim--) { 
    for (var num:Number = 1; num <= lim, num++) { 
     doSomethingWith(num); 
    } 
} 
+1

與AS3和AIR可以爲iOS和Android創建應用程序,網絡已經被超越。 – esdebon

0
var x:int = 5; 
while(x > 0) { 
     var output:String = ""; 
     for(var i:int = x; i > 0; i--) { 
      output = i + " " + output; 
      x--; 
     } 
     trace(output); 
} 
0
//Here the variable to build the string to "print" 
var str:String=""; 

//We need two loops 
//The first to change the row 

for (var lim:int= 5; lim > 0; lim--) { 

    //Reset the string each new row 
    str=""; 

    //And here the scond to build the string to "print" 
    for (var num:int= 1; num <= lim; num++) { 
     str+=num+" "; 
    } 

    //Here "print" the string 
    trace(str); 
} 
+0

雖然此代碼片段可能會解決問題,但[包括解釋](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)確實有助於提高帖子的質量。請記住,您將來會爲讀者回答問題,而這些人可能不知道您的代碼建議的原因。 –

0

這是我的代碼來創建一個這樣的模式:

for (var i:int = 5; i >= 1; i--) { // represent the row 
    trace("1"); // print first element 
    for (var j:int = 2; j <= i; j++) { // represet the line 
     trace(" " + j.toString()); // print space and a number 
    } 
    trace("\n"); //next line 
}