Multiple if statements

Sep 17, 2011 at 11:33pm
I'm trying to make a text based adventure game and I would like the player to pick a class. Is it possible to make multiple if statements and one else statement?
Sep 17, 2011 at 11:50pm
An else statement can only have one paired if statement. If you want to have multiple conditions where only one condition is taken, you can do an "else if chain":

1
2
3
4
5
6
7
8
9
10
11
12
if(foo)
{
  // happens only if foo is true
}
else if(bar)
{
  // happens only if foo is false and bar is true
}
else
{
  // happens only if foo and bar are both false
}
Sep 17, 2011 at 11:52pm
Thanks!
Topic archived. No new replies allowed.