mirror of
https://github.com/rust-lang/book.git
synced 2026-11-30 20:24:32 -06:00
Merge pull request #392 from spastorino/compiler_do_not_execute_code
The compiler doesn't execute at runtime
This commit is contained in:
@@ -387,9 +387,9 @@ will reach a value of `5` at some point, the loop stops executing before trying
|
|||||||
to fetch a sixth value from the array.
|
to fetch a sixth value from the array.
|
||||||
|
|
||||||
But this approach is error prone; we could cause the program to panic if the
|
But this approach is error prone; we could cause the program to panic if the
|
||||||
index length is incorrect. It’s also slow, because the compiler needs to
|
index length is incorrect. It’s also slow, because the compiler adds
|
||||||
perform the conditional check on every element on every iteration through the
|
runtime code to perform the conditional check on every element on every
|
||||||
loop.
|
iteration through the loop.
|
||||||
|
|
||||||
As a more efficient alternative, you can use a `for` loop and execute some code
|
As a more efficient alternative, you can use a `for` loop and execute some code
|
||||||
for each item in a collection. A `for` loop looks like this:
|
for each item in a collection. A `for` loop looks like this:
|
||||||
|
|||||||
Reference in New Issue
Block a user