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 
}