Delete dead file, add block stmt
This commit is contained in:
parent
7715adfebc
commit
6378b101bf
2 changed files with 9 additions and 44 deletions
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
Nimrod many different control flow constructs, including the standard `if`s, `else`s, and `while`s.
|
Nimrod many different control flow constructs, including the standard `if`s, `else`s, and `while`s.
|
||||||
|
|
||||||
|
When inside a loop or block, it is possible to use `continue` or `break` any point, where `continue` skips to the next iteration and `break` ends the loop. The break statement can also receive the name of the block to break out of, so it is possible to break out of nested loops.
|
||||||
|
|
||||||
``` Nimrod
|
``` Nimrod
|
||||||
import strutils
|
import strutils
|
||||||
|
|
||||||
let
|
let answer = 4 # Chosen by a fair dice roll,
|
||||||
answer = 4 # Chosen by a fair dice roll,
|
|
||||||
# guaranteed to be random
|
# guaranteed to be random
|
||||||
|
|
||||||
while true:
|
while true:
|
||||||
echo "I have a number from 1 to 10, what is it? "
|
echo "I have a number from 1 to 10, what is it? "
|
||||||
let guess = parseInt(stdin.readLine)
|
let guess = parseInt(stdin.readLine)
|
||||||
|
|
@ -20,6 +20,9 @@ while true:
|
||||||
else:
|
else:
|
||||||
echo "Correct!"
|
echo "Correct!"
|
||||||
break
|
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.
|
block busyloops:
|
||||||
|
while true:
|
||||||
|
while true:
|
||||||
|
break busyloops
|
||||||
|
```
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
# Assignment
|
|
||||||
|
|
||||||
Nimrod supports three different types of variables, `let`, `var`, and `const`. As with most things, multiple variables can be declared in the same section.
|
|
||||||
|
|
||||||
``` nimrod
|
|
||||||
proc getLetterA(): string =
|
|
||||||
result = ""
|
|
||||||
for letter in 'a'..'z':
|
|
||||||
result.add(letter)
|
|
||||||
|
|
||||||
const abcs = getLetterA()
|
|
||||||
var
|
|
||||||
foo = "bar"
|
|
||||||
bar = "foo"
|
|
||||||
# oops, I need to fix the names
|
|
||||||
let temp = foo
|
|
||||||
foo = bar
|
|
||||||
bar = temp
|
|
||||||
|
|
||||||
echo "abcs is ", abcs
|
|
||||||
echo "foo is ", foo
|
|
||||||
echo "bar is ", bar
|
|
||||||
```
|
|
||||||
|
|
||||||
```
|
|
||||||
$ nimrod c -r ./assignment.nim
|
|
||||||
abcs is abcdefghijklmnopqrstuvwxyz
|
|
||||||
foo is foo
|
|
||||||
bar is bar
|
|
||||||
```
|
|
||||||
|
|
||||||
A `const` variable is evaluated at compile-time, so if you inspect the C sources, you'll see the following line:
|
|
||||||
|
|
||||||
``` C
|
|
||||||
STRING_LITERAL(TMP129, "abcdefghijklmnopqrstuvwxyz", 26);
|
|
||||||
```
|
|
||||||
|
|
||||||
`var` variables are the standard mutable variables, you can modify them after they've been assigned. `let` variables are also fairly standard immutable variables. This means you can assign to them at creation time and can't change them later on.
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue