else if statements query

For everyone, just starting with C++ or programming at all. Ask newbie questions in this forum!

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

else if statements query

Postby zushiko » Mon Apr 09, 2012 11:34 am

can I make an else if statement in another else if statement? Its like I have option "A" and "B" and when you choose "A" you will have to choose again from option "A.1" something like that?
zushiko
 
Posts: 9
Joined: Fri Mar 16, 2012 10:48 pm

Re: else if statements query

Postby Wizard » Mon Apr 09, 2012 3:18 pm

Absolutely.
Code: Select all
if (option == 'A')
{
    if (option2 == '1')
    {
        // do stuff
    } else
    {
        // do other stuff
    }
} else
{
    // do option B stuff
}
User avatar
Wizard
Site Admin
 
Posts: 3226
Joined: Mon Sep 22, 2003 4:52 pm
Location: ON, CA

Re: else if statements query

Postby joshcschool » Wed May 09, 2012 6:22 pm

yes you can , an easy example is this.


Code: Select all
if (condition1)
  {
  code to be executed if condition1 is true
  }
else if (condition2)
  {
  code to be executed if condition2 is true
  }
else
  {
  code to be executed if neither condition1 nor condition2 is true
  }
joshcschool
 
Posts: 3
Joined: Wed May 09, 2012 6:12 pm


Return to For Beginners

Who is online

Users browsing this forum: No registered users and 1 guest