add information and minor restructuring
This commit is contained in:
parent
95493e61bc
commit
7715adfebc
5 changed files with 9 additions and 7 deletions
25
src/if_else_while.md
Normal file
25
src/if_else_while.md
Normal 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.
|
||||
Loading…
Add table
Add a link
Reference in a new issue