-
Notifications
You must be signed in to change notification settings - Fork 388
Description
In the book, in Section 20 "Copy types", there is a sentence discussing the provided code example that seems to contain a typo. The sentence refers to a "loop" when it should refer to a "block."
Affected Text
The problematic sentence is:
You can see that my_number was declared in the main() function, so it lives until the end. But it gets its value from inside a loop. However, that value lives as long as my_number, because my_number has the value. And if you wrote let my_number = loop_then_return(number) inside the block, it would just die right away.
Issue
The sentence "But it gets its value from inside a loop" is incorrect. The value of my_number
is assigned inside a block (denoted by {}
) in the main
function, not inside a loop
. The loop
construct is used in the loop_then_return
function, but this is not relevant to the context of the sentence, which describes the assignment of my_number
in the main
function.
Suggested Fix
Replace the sentence:
But it gets its value from inside a loop.
With:
But it gets its value from inside a block.
Code Context
The relevant code example in the book is:
fn loop_then_return(mut counter: i32) -> i32 {
loop {
counter += 1;
if counter % 50 == 0 {
break;
}
}
counter
}
fn main() {
let my_number;
{
// Pretend we need to have this code block
let number = {
// Pretend there is code here to make a number
// Lots of code, and finally:
57
};
my_number = loop_then_return(number);
}
println!("{}", my_number);
}
Additional Notes
This change ensures clarity and accuracy, as the term "block" correctly describes the scope where my_number is assigned its value. The current wording may confuse readers, as it incorrectly suggests that the assignment happens inside a loop construct.
Thank you for considering this correction!