Skip to content

Commit 436c966

Browse files
mzaffalonstevengjvtjnashDilumAluthge
authored andcommitted
Show use of let without immediate assignment (JuliaLang#43094)
Co-authored-by: Steven G. Johnson <[email protected]> Co-authored-by: Jameson Nash <[email protected]> Co-authored-by: Dilum Aluthge <[email protected]> Co-authored-by: Steven G. Johnson <[email protected]>
1 parent 983a76e commit 436c966

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

doc/src/manual/variables-and-scoping.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,20 @@ file, if it behaves differently than it did in the REPL, then you will get a war
526526
### Let Blocks
527527

528528
`let` statements create a new *hard scope* block (see above) and introduce new variable
529-
bindings each time they run. Whereas assignments might reassign a new value to an existing value location,
530-
`let` always creates a new location.
531-
This difference is usually not important, and is only detectable in the case of variables that
532-
outlive their scope via closures. The `let` syntax accepts a comma-separated series of assignments
533-
and variable names:
529+
bindings each time they run. The variable need not be immediately assigned:
530+
```jldoctest
531+
julia> var1 = let x
532+
for i in 1:5
533+
(i == 4) && (x = i; break)
534+
end
535+
x
536+
end
537+
4
538+
```
539+
Whereas assignments might reassign a new value to an existing value location, `let` always creates a
540+
new location. This difference is usually not important, and is only detectable in the case of
541+
variables that outlive their scope via closures. The `let` syntax accepts a comma-separated series of
542+
assignments and variable names:
534543

535544
```jldoctest
536545
julia> x, y, z = -1, -1, -1;

0 commit comments

Comments
 (0)