--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Loops/Break
+#
+# SEE: http://rosettacode.org/wiki/Loops/Break
+module loops_break
+
+loop
+ var a = 20.rand
+ print a
+ if a == 10 then break
+ print 20.rand
+end
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Loops/Continue
+#
+# SEE: http://rosettacode.org/wiki/Loops/Continue
+module loops_continue
+
+for i in [1..10] do
+ printn i
+ if i % 5 == 0 then
+ printn "\n"
+ continue
+ end
+ printn ", "
+end
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Loops/Do-while
+#
+# SEE: http://rosettacode.org/wiki/Loops/Do-while
+module loops_do_while
+
+var val = 0
+loop
+ val += 1
+ print val
+ if val % 6 == 0 then break
+end
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Loops/Downward for
+#
+# SEE: http://rosettacode.org/wiki/Loops/Downward_for
+module loops_downward_for
+
+for i in [0..10].reverse_iterator do
+ print i
+end
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Loops/For
+#
+# SEE: http://rosettacode.org/wiki/Loops/For
+module loops_for
+
+for i in [1..5] do
+ for j in [1..i] do printn "*"
+ print ""
+end
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Loops/Infinite
+#
+# SEE: http://rosettacode.org/wiki/Loops/Infinite
+module loops_infinite
+
+loop print "SPAM"
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Loops/n + 1/2
+#
+# SEE: http://rosettacode.org/wiki/Loops/N_plus_one_half
+module loops_n_plus_one_half
+
+for i in [0..10] do
+ printn i
+ if i == 10 then break
+ printn ", "
+end
+print ""
+
+# Here the idiomatic version using `join`
+print([0..10].join(", "))
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Loops/While
+#
+# SEE: http://rosettacode.org/wiki/Loops/While
+module loops_while
+
+var i = 2014
+while i > 0 do
+ print i
+ i /= 2
+end
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Read entire file
+#
+# SEE: http://rosettacode.org/wiki/Read_entire_file
+module read_entire_file
+
+var filename = "/etc/issue"
+var content = filename.to_path.read_all
+print content
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Tree traversal
+#
+# SEE: http://rosettacode.org/wiki/Tree_traversal
+module tree_traversal
+
+class Node
+ var value: Int
+ var left: nullable Node
+ var right: nullable Node
+
+ fun preorder
+ do
+ print value
+ var l = left
+ if l != null then l.preorder
+ var r = right
+ if r != null then r.preorder
+ end
+
+ fun inorder
+ do
+ var l = left
+ if l != null then l.inorder
+ print value
+ var r = right
+ if r != null then r.inorder
+ end
+
+ fun postorder
+ do
+ var l = left
+ if l != null then l.postorder
+ var r = right
+ if r != null then r.postorder
+ print value
+ end
+
+ fun levelorder
+ do
+ var q = new List[Node]
+ q.add self
+ while q.not_empty do
+ var n = q.shift
+ print n.value
+ var l = n.left
+ if l != null then q.push l
+ var r = n.right
+ if r != null then q.push r
+ end
+ end
+end
+
+var tree = new Node(1,
+ new Node(2,
+ new Node(4,
+ new Node(7)),
+ new Node(5)),
+ new Node(3,
+ new Node(6,
+ new Node(8),
+ new Node(9))))
+
+print "preorder:"
+tree.preorder
+print "inorder:"
+tree.inorder
+print "postorder:"
+tree.postorder
+print "levelorder:"
+tree.levelorder
converter
show_basedir
langannot
+loops_infinite
+read_entire_file
--- /dev/null
+16
+7
+15
+15
+18
+3
+6
+15
+5
+11
+9
+12
+7
+10
+19
+18
+12
+14
+2
+12
+0
+4
+2
+16
+3
+8
+2
+2
+19
+4
+10
--- /dev/null
+1, 2, 3, 4, 5
+6, 7, 8, 9, 10
--- /dev/null
+1
+2
+3
+4
+5
+6
--- /dev/null
+10
+9
+8
+7
+6
+5
+4
+3
+2
+1
+0
--- /dev/null
+*
+**
+***
+****
+*****
--- /dev/null
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
--- /dev/null
+2014
+1007
+503
+251
+125
+62
+31
+15
+7
+3
+1
--- /dev/null
+preorder:
+1
+2
+4
+7
+5
+3
+6
+8
+9
+inorder:
+7
+4
+2
+5
+1
+8
+6
+9
+3
+postorder:
+7
+4
+5
+2
+8
+9
+6
+3
+1
+levelorder:
+1
+2
+3
+4
+5
+6
+7
+8
+9