add information and minor restructuring

This commit is contained in:
flaviut 2014-05-29 17:46:44 -04:00
commit 7715adfebc
5 changed files with 9 additions and 7 deletions

25
src/if_else_while.md Normal file
View file

@ -0,0 +1,25 @@
# If, Else, While, Block
Nimrod many different control flow constructs, including the standard `if`s, `else`s, and `while`s.
``` Nimrod
import strutils
let
answer = 4 # Chosen by a fair dice roll,
# guaranteed to be random
while true:
echo "I have a number from 1 to 10, what is it? "
let guess = parseInt(stdin.readLine)
if guess < answer:
echo "Too low, try again"
elif guess > answer:
echo "Too high, try again"
else:
echo "Correct!"
break
```
When inside a loop, it is possible to use `continue` or `break` any point within the loop with the standard semantics, where `continue` skips to the next iteration and `break` ends the loop.