if what you compare in those if-statements are integertype values you can use switch and case instead. Example of this:
Code:
int main()
{
int a=0;
switch(a)
{
case 1:
// do something
break; // This is needed otherwise it will "fall through", explenation below.
case 2:
// do something else
break;
case 0:
return 0;
}
What is meant with fall through:
Consider this code:
Code:
#include <iostream>
int main()
{
int a;
std::cin >> a;
switch(a)
{
case 1:
std::cout << "a = 1" << std::endl;
break;
case 2:
std::cout << "a = 2" << std::endl;
// notice: no break statement here.
case 0:
std::cout << "a = 0" << std::endl;
break;
default:
std::cout << "Default action taken." << std::endl;
break;
}
If you in this piece of code input 1 output will be:
a = 1
If you input 2 ouput will be:
a = 2
a = 0
If you input something else output will be:
Default action taken.
Basicly the program will just start at the first case that matches and then it will go through all the other cases (even if they arent correct) and do what is in those until it hits a break or until no more cases are given.