If and statement?

I know this is probably a stupid question but I haven't slept in 50 years so gimme a break lol. Anyway how do you write an if and statement?

Example of what I mean:
if (variableOne == 0) and (variableTwo == 0)
functionOne();
1
2
3
4
if ( (variableOne == 0) && (variableTwo == 0) )
{
    functionOne();
}
Your entire condition needs to be enclosed in parentheses, so:

1
2
if ((variableOne == 0) and (variableTwo == 0))
  functionOne(); 


The word "and" will work here, but it's actually very unusual to use it. It's much more idiomatic in C++ to use &&, so:

1
2
if ((variableOne == 0) && (variableTwo == 0))
  functionOne(); 


This site has tons of tutorial information on stuff like this, if there's more that you need to know.

Edit: and ninja'd again.
Last edited on
Topic archived. No new replies allowed.