diff options
| author | Cody <cody@codyq.dev> | 2023-06-24 21:11:44 -0500 |
|---|---|---|
| committer | Cody <cody@codyq.dev> | 2023-06-24 21:11:44 -0500 |
| commit | def8adfcb9a9572f4e030990626a0d08377118bd (patch) | |
| tree | f230fdf3d281f3f9a91f0510d954344f2bdb48ce /examples | |
| parent | 0ee365c80667a3a5f43a86ead75fd0da5be23282 (diff) | |
| download | sloth-def8adfcb9a9572f4e030990626a0d08377118bd.tar.gz | |
hehehaha
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/guessing.sloth | 47 | ||||
| -rw-r--r-- | examples/hello.sloth | 2 |
2 files changed, 27 insertions, 22 deletions
diff --git a/examples/guessing.sloth b/examples/guessing.sloth index 05c25db..5a759e5 100644 --- a/examples/guessing.sloth +++ b/examples/guessing.sloth @@ -1,26 +1,29 @@ -val computer: int = random(1, 10); +foreign fn print(); +foreign fn println(); +foreign fn readln() String; +foreign fn random(min: Int, max: Int) Int; +foreign fn parse_int(str: String) Int; -var tries: int = 0; -var correct: bool = false; +fn main() { + var computer: Int = random(1, 10); + var tries: Int = 0; + var correct: Bool = false; -while !correct { - print("\nPick a number between 1 and 10: "); - val human: int = parse_int(readln()); + while !correct { + print("Pick a number between 1 and 10: "); + var human: Int = parse_int(readln()); - if human == computer { - println("You guessed the same number as me!"); - correct = true; - } - - if human > computer { - println("Your guess was too high."); - } - - if human < computer { - println("Your guess was too low."); - } - - tries = tries + 1; -} + if human == computer { + println("You guessed the same number as me!\n"); + correct = true; + } else if human > computer { + println("Your guess was too high.\n"); + } else if human < computer { + println("Your guess was too low.\n"); + } + + tries = tries + 1; + } -println("\nIt took you ", tries, " tries to guess correctly!"); + println("It took you ", tries, " tries to guess correctly!"); +} diff --git a/examples/hello.sloth b/examples/hello.sloth index 8b395e8..a955e66 100644 --- a/examples/hello.sloth +++ b/examples/hello.sloth @@ -1,3 +1,5 @@ +foreign fn example(arg: Int) Void; + fn main() { var i: Int = 10; var j: Int = 1.0 - 1; |
