From 109c3f033c0758ea04477aba5c5dd0ac75c0584c Mon Sep 17 00:00:00 2001 From: Jeff Date: Sat, 18 May 2024 11:59:39 -0400 Subject: [PATCH] Clean up example --- README.md | 21 +++++++++++++++++++++ examples/guessing_game.ds | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ae67285..8e6d8e7 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,24 @@ High-level programming language with effortless concurrency, automatic memory management, type safety and advanced error handling. +```dust +io.write_line("Guess the number.") + +secret_number = random.range(0..100) + +loop { + io.write_line("Input your guess.") + + input = io.read_line() + guess = int.parse(input) + + if guess < secret_number { + io.write_line("Too low!") + } else if guess > secret_number { + io.write_line("Too high!") + } else { + io.write_line("You win!") + break + } +} +``` diff --git a/examples/guessing_game.ds b/examples/guessing_game.ds index ef4404a..d99fa77 100644 --- a/examples/guessing_game.ds +++ b/examples/guessing_game.ds @@ -5,8 +5,8 @@ secret_number = int.random_range(0..100) loop { io.write_line("Input your guess.") - input = io.read_line() ? io.write_line("Failed to read input.") - guess = int.parse(input) ? io.write_line("Failed to parse input.") + input = io.read_line() + guess = int.parse(input) if guess < secret_number { io.write_line("Too low!")