I am new to Action Script programming Language, and I want to create the following number pattern:
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
How can I code this pattern in Action Script Language?
I'm surprised anyone's starting to learn ActionScript (assuming you're using it for Flash) when the rest of the planet is moving toward HTML5 but, to each their own :-)
The algorithm you want for that sequence is relatively simple, and should be simple to convert into any procedural language:
for limit = 5 to 1 inclusive, stepping by -1:
for number = 1 to limit inclusive, stepping by 1:
output number
output newline
That's basically it. Based on my (very) limited exposure to AS3, that would come out as something like:
for (var lim:Number = 5; lim > 0, lim--) {
for (var num:Number = 1; num <= lim, num++) {
doSomethingWith(num);
}
}
//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);
}