From 023a67949e46523f13695982eeafa51af099beb0 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 15 Apr 2011 15:04:33 +0200 Subject: [PATCH] nicer bottles --- examples/src/Bottles.jetl | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/examples/src/Bottles.jetl b/examples/src/Bottles.jetl index 8ae5408d13b..a0293624b5b 100644 --- a/examples/src/Bottles.jetl +++ b/examples/src/Bottles.jetl @@ -3,25 +3,21 @@ namespace bottles; fun main(args: Array) { var bottles: Int = 99; while(bottles > 0) { - System.out?.print(bottlesOfBeer(bottles)) - System.out?.print(" on the wall, ") - System.out?.print(bottlesOfBeer(bottles)) - System.out?.println(".") + System.out?.print(bottlesOfBeer(bottles) + " on the wall, ") + System.out?.println(bottlesOfBeer(bottles) + ".") System.out?.print("Take one down, pass it around, ") - bottles -= 1; - if (bottles == 0) { - System.out?.print("no more bottles of beer on the wall.") + if (--bottles == 0) { + System.out?.println("no more bottles of beer on the wall.") } else { - System.out?.print(bottlesOfBeer(bottles)) - System.out?.println(" on the wall.") + System.out?.println(bottlesOfBeer(bottles) + " on the wall.") } } } -fun bottlesOfBeer(count: Int): String? { - val result = new StringBuilder() - result.append(count) - result.append(if (count > 1) " bottles of beer" else " bottle of beer") - return result.toString() +fun bottlesOfBeer(count: Int): String { + val result = new StringBuilder() + result.append(count) + result.append(if (count > 1) " bottles of beer" else " bottle of beer") + return result.toString() ?: "" }