Updated variables/result.md
This commit is contained in:
parent
b308f5f443
commit
08a8ca6126
1 changed files with 4 additions and 4 deletions
|
|
@ -1,15 +1,15 @@
|
||||||
# Result
|
# Result
|
||||||
|
|
||||||
The `result` variable is a special variable that serves as an implicit return. This is useful because in most cases, the control flow semantics of the `return` statement are unneeded. `result` is initialized with the default value for a given return type, so the the following code it starts as `0`, before being initialized to `number`
|
The `result` variable is a special variable that serves as an implicit return variable. This is useful because in most cases, the control flow semantics of the `return` statement are unneeded. `result` is initialized with the default value for a given return type, so the following code starts as `0`, before being initialized to `number`:
|
||||||
|
|
||||||
``` nimrod
|
``` nimrod
|
||||||
proc expr(number, power: int): int =
|
proc `**`(number, power: int): int =
|
||||||
result = number
|
result = number
|
||||||
for i in 1..power:
|
for i in 1..power:
|
||||||
result *= number
|
result *= number
|
||||||
```
|
```
|
||||||
|
|
||||||
A common gotcha is declaring a variable called result and expecting it to have the same semantics.
|
A possible gotcha is declaring a variable called result and expecting it to have the same semantics.
|
||||||
|
|
||||||
``` nimrod
|
``` nimrod
|
||||||
proc unexpected(): int =
|
proc unexpected(): int =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue