diff --git a/src/variables/result.md b/src/variables/result.md index 8ffb402..82b950d 100644 --- a/src/variables/result.md +++ b/src/variables/result.md @@ -1,15 +1,15 @@ # 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 -proc expr(number, power: int): int = +proc `**`(number, power: int): int = result = number for i in 1..power: 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 proc unexpected(): int = @@ -17,4 +17,4 @@ proc unexpected(): int = result += 5 echo unexpected() # Prints 0, not 10 -``` \ No newline at end of file +```