Skip to content

Instantly share code, notes, and snippets.

@elsassph
Forked from xitij2000/10squares.hx.js
Created December 30, 2011 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elsassph/1539045 to your computer and use it in GitHub Desktop.
Save elsassph/1539045 to your computer and use it in GitHub Desktop.
haXe code to print squares of first 10 numbers.
Main.main = function() {
js.Lib.document.write(Main.square(10).join(","));
}
Main.square = function(n) {
var result = [];
var _g = 0;
while(_g < n) {
var i = _g++;
result.push(i * i);
}
return result;
}
package;
import js.Lib;
class Main {
public static function main() {
Lib.document.write(square(10).join(","));
}
public static function square(n:Int) {
var result = [];
for (i in 0...n) {
result.push(i * i);
}
return result; // inferred as Array<Int> by the compiler
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment