# if statement

Page 1 of 1

## 6 Replies - 361 Views - Last Post: 16 March 2011 - 03:34 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=222340&amp;s=f77d051c52a5dc4525f3f9b81cc7e97f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 lokyblue

Reputation: 0
• Posts: 26
• Joined: 23-March 10

# if statement

Posted 15 March 2011 - 03:37 PM

i cant use this code like this
```
if!(num2 > num4){

temp=num2;

num2=num4;

num4=temp;

}

```

should i just use < or is there a syntax to wright this code properly?
Is This A Good Question/Topic? 0

## Replies To: if statement

### #2 skyhawk133

Reputation: 1910
• Posts: 20,337
• Joined: 17-March 01

## Re: if statement

Posted 15 March 2011 - 03:39 PM

So you're trying to do "if not greater than" ?

### #3 lokyblue

Reputation: 0
• Posts: 26
• Joined: 23-March 10

## Re: if statement

Posted 15 March 2011 - 03:42 PM

exactly i can use just if (num2 < num4 ) but is there a way to wright as if!(num2 > num4)

### #4 skyhawk133

Reputation: 1910
• Posts: 20,337
• Joined: 17-March 01

## Re: if statement

Posted 15 March 2011 - 03:46 PM

That's what the < operator is for, alternatively, you could say num4 > num2 if you're just dead set on using the greater than operator. I'll let someone more familiar with C++ specifically chime in, but I don't believe you can create a conditional using the ! like that. You may be able to do if(!(num2 > num4))??

### #5 lokyblue

Reputation: 0
• Posts: 26
• Joined: 23-March 10

## Re: if statement

Posted 15 March 2011 - 03:48 PM

i will try but thanks anyway

### #6 jimblumberg

Reputation: 4894
• Posts: 15,283
• Joined: 25-December 09

## Re: if statement

Posted 15 March 2011 - 05:15 PM

You can use the != operator to test for inequality if(num4 != num2).

Jim

### #7 janotte

• code > sword

Reputation: 990
• Posts: 5,141
• Joined: 28-September 06

## Re: if statement

Posted 16 March 2011 - 03:34 AM

Lets try some simple logic.

If x is not greater than y then x must be less than or equal to y.

So if you wanted to test for "is not greater than" just use "is less than or equal to". Like this
```if(x <= y){
// do stuff
}
```