Skip to content

Add documentation for else if to trpl #22515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/doc/trpl/if.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 :(");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be nor instead of or

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would write "x is not five or six" or "x is five nor six", but the second sounds archaic to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI https://english.stackexchange.com/questions/10049/usage-of-neither-nor-versus-not-or

I'm not going to spend too much time defending my suggestion here, but I stand by not...nor

}
```

This is all pretty standard. However, you can also do this:


Expand Down