diff --git a/src/SUMMARY.md b/src/SUMMARY.md index b3c4b2ac3..39dd8152e 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -13,7 +13,7 @@ - [Scalar Types](scalar-types.md) - [Compound Types](compound-types.md) - [Comments](comments.md) - - [`if`](if.md) + - [Control flow with `if`](if.md) - [Loops](loops.md) - [Ownership & borrowing](ownership-and-borrowing.md) diff --git a/src/if.md b/src/if.md index ad2c6679d..aa0c22e10 100644 --- a/src/if.md +++ b/src/if.md @@ -1,4 +1,4 @@ -# if +# Control flow with `if` > Two roads diverged in a yellow wood, > And sorry I could not travel both @@ -8,13 +8,6 @@ > > - Robert Frost, “The Road Not Taken” -One of the most primitive operations in computer programming is the ability to -‘branch’ between two different code paths. A program can look at a value, and -then decide: should I follow this path, or should I take the other? There’s -actually two different metaphors here: a tree, whose branches come from the -same, single trunk. And a road, which splits off into two, each going in a -different direction. - In Rust, there are a few ways to cause our code to branch. The most fundamental way is by using `if`. An `if` expression gives us two paths forward, and asks the question, “Which one should I take?” @@ -218,7 +211,4 @@ error: aborting due to previous error Could not compile `branches`. ``` -`if` and `else` have incompatible types. This can’t work. This also -means that you almost certainly need an `else` when using `if` in -this way. If you don’t, what would the value be if the condition was -false? +`if` and `else` have incompatible types. This can’t work.