Two Conditions For "if"

Hello. I am wondering if it is possible to have two conditions for an if statement. It would be some thing like:

int a = 1 ;
int b = 2 ;
if (//a = 1 and b = 2, how do you write this?)
{
blah blah blah
}
Any replies would be appreciated. Thank you!
1
2
3
4
5
if (a == 1 || b == 2 ){

write the statement

}
1
2
3
4
if (a == 1 && b == 2)
{
//write the statement
}


|| is the or operator && is the and operator.
Actually, helnow didn't quite read your post correctly. His example checks a=1 or b=2. || is the boolean OR operator. To get a= 1 and b=2 you need the AND operator &&:

1
2
3
4
5
   if (a == 1 && b == 2 ){

   write the statement

   }
closed account (Dy7SLyTq)
#include <iso646.h>

if(a and b or b and a)
What is the purpose of that code DTSCode?
closed account (Dy7SLyTq)
showing another way to do it. its meant for people that use different character set (hence the word iso) so if he was from say germany then it would still keep it c++ compliant
I meant the a and b or b and a he was trying to do a == 1 and b == 2
closed account (Dy7SLyTq)
i was just showing an example of and and or without multiple ifs.
Thanks everyone!
Topic archived. No new replies allowed.