Skip to content

Commit cec404a

Browse files
committed
Add documentation for else if to trpl
Adds an example of `else if` to the If section of The Rust Programming Language. r? @steveklabnik
1 parent dfc5c0f commit cec404a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/doc/trpl/if.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ if x == 5 {
3434
}
3535
```
3636

37+
If there is more than one case, use an `else if`:
38+
39+
```rust
40+
let x = 5;
41+
42+
if x == 5 {
43+
println!("x is five!");
44+
} else if x == 6 {
45+
println!("x is six!");
46+
} else {
47+
println!("x is not five or six :(");
48+
}
49+
```
50+
3751
This is all pretty standard. However, you can also do this:
3852

3953

0 commit comments

Comments
 (0)