From cec404a0663509c4075a08d85887ca85fa6f8dff Mon Sep 17 00:00:00 2001 From: Adam Jacob Date: Wed, 18 Feb 2015 16:15:32 -0800 Subject: [PATCH] Add documentation for `else if` to trpl Adds an example of `else if` to the If section of The Rust Programming Language. r? @steveklabnik --- src/doc/trpl/if.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/doc/trpl/if.md b/src/doc/trpl/if.md index a350df67b17..7dac49987d8 100644 --- a/src/doc/trpl/if.md +++ b/src/doc/trpl/if.md @@ -34,6 +34,20 @@ if x == 5 { } ``` +If there is more than one case, use an `else if`: + +```rust +let x = 5; + +if x == 5 { + println!("x is five!"); +} else if x == 6 { + println!("x is six!"); +} else { + println!("x is not five or six :("); +} +``` + This is all pretty standard. However, you can also do this: