diff --git a/src/ch03-05-control-flow.md b/src/ch03-05-control-flow.md index 6bde6748fe..8259eddae2 100644 --- a/src/ch03-05-control-flow.md +++ b/src/ch03-05-control-flow.md @@ -242,16 +242,9 @@ can use it, as shown here: {{#rustdoc_include ../listings/ch03-common-programming-concepts/no-listing-33-return-value-from-loop/src/main.rs}} ``` -Before the loop, we declare a variable named `counter` and initialize it to -`0`. Then, we declare a variable named `result` to hold the value returned from -the loop. On every iteration of the loop, we add `1` to the `counter` variable, -and then check whether the `counter` is equal to `10`. When it is, we use the -`break` keyword with the value `counter * 2`. After the loop, we use a -semicolon to end the statement that assigns the value to `result`. Finally, we -print the value in `result`, which in this case is `20`. - -You can also `return` from inside a loop. While `break` only exits the current -loop, `return` always exits the current function. +Before the loop, we declare a variable named counter and initialize it to 0. Then, we declare a variable named result to hold the value returned from the loop. On every iteration of the loop, we add 1 to the counter variable, and then check whether the counter is equal to 10. When it is, we use the break keyword with the value counter * 2, which exits the loop and supplies that value as the result of the loop expression. The break statement can be written with or without a trailing semicolon because it immediately transfers control flow out of the loop, so the semicolon does not affect the value being returned. After the loop, we use a semicolon to end the statement that assigns the value to result. Finally, we print the value in result, which in this case is 20. + +You can also return from inside a loop. While break only exits the current loop, return always exits the current function. diff --git a/src/ch08-03-hash-maps.md b/src/ch08-03-hash-maps.md index 696216245f..51037fc047 100644 --- a/src/ch08-03-hash-maps.md +++ b/src/ch08-03-hash-maps.md @@ -169,11 +169,11 @@ inserts the parameter as the new value for this key and returns a mutable reference to the new value. This technique is much cleaner than writing the logic ourselves and, in addition, plays more nicely with the borrow checker. -Running the code in Listing 8-24 will print `{"Yellow": 50, "Blue": 10}`. The -first call to `entry` will insert the key for the Yellow team with the value -`50` because the Yellow team doesn’t have a value already. The second call to -`entry` will not change the hash map, because the Blue team already has the -value `10`. +Running the code in Listing 8-24 will print `{"Blue": 10, "Yellow": 50}`. The +first call to `insert` will add the first value for the Blue team. Then the call +to `entry` will insert the key for the Yellow team with the value `50` because +the Yellow team doesn’t have a value already. The second call to `entry` will not +change the hashmap , because the Blue team already has the value `10`. #### Updating a Value Based on the Old Value