diff --git a/src/if_else_while.md b/src/if_else_while.md index e978e96..e94e321 100644 --- a/src/if_else_while.md +++ b/src/if_else_while.md @@ -2,13 +2,13 @@ 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 import strutils -let - answer = 4 # Chosen by a fair dice roll, - # guaranteed to be random - +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) @@ -20,6 +20,9 @@ while true: 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. \ No newline at end of file +block busyloops: + while true: + while true: + break busyloops +``` \ No newline at end of file diff --git a/src/variables.md b/src/variables.md deleted file mode 100644 index aef636f..0000000 --- a/src/variables.md +++ /dev/null @@ -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. \ No newline at end of file