# difference between <= and =

Page 1 of 1

## 8 Replies - 477 Views - Last Post: 21 September 2012 - 08:02 PMRate 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=292763&amp;s=04495b4190deac8d9bc1568c22ee7706&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 iheartbreakz

Reputation: 1
• Posts: 196
• Joined: 27-April 11

# difference between <= and =

Posted 21 September 2012 - 03:47 PM

Can anyone tell me the difference between these 2 functions
if(\$this->itemCount <= 0) and if(\$this->itemCount = 0)

both of them are giving me different results but wouldn't <= 0 and = 0 mean the same thing?
Is This A Good Question/Topic? 0

## Replies To: difference between <= and =

### #2 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11312
• Posts: 42,611
• Joined: 27-December 08

## Re: difference between <= and =

Posted 21 September 2012 - 03:50 PM

The = operator is for assignments, and the == operator is for comparisons. Mathematically, less than or equal to has a different meaning than equal to. The meanings are pretty obvious.

### #3 iheartbreakz

Reputation: 1
• Posts: 196
• Joined: 27-April 11

## Re: difference between <= and =

Posted 21 September 2012 - 03:53 PM

yea i knew that but my question is wouldnt <= mean less than OR equal to?

### #4 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11312
• Posts: 42,611
• Joined: 27-December 08

## Re: difference between <= and =

Posted 21 September 2012 - 03:56 PM

Yes, that is correct.

• Saucy!

Reputation: 6193
• Posts: 23,920
• Joined: 23-August 08

## Re: difference between <= and =

Posted 21 September 2012 - 04:37 PM

if(\$this->itemCount <= 0) and if(\$this->itemCount = 0)

That code is not even valid code.

### #6 creativecoding

• Hash != Encryption

Reputation: 928
• Posts: 3,213
• Joined: 19-January 10

## Re: difference between <= and =

Posted 21 September 2012 - 04:46 PM

What part about that isn't valid code?

### #7 Atli

Reputation: 3853
• Posts: 6,356
• Joined: 08-June 10

## Re: difference between <= and =

Posted 21 September 2012 - 05:00 PM

The and would be invalid in that position, although I suspect that was more for our benefit than meant to represent actual code.

### #8 iheartbreakz

Reputation: 1
• Posts: 196
• Joined: 27-April 11

## Re: difference between <= and =

Posted 21 September 2012 - 07:52 PM

lol i asked it as a question ... shoulda put 2 [code] tags there.. sorry

### #9 xclite

• I wrote you an code

Reputation: 982
• Posts: 3,448
• Joined: 12-May 09

## Re: difference between <= and =

Posted 21 September 2012 - 08:02 PM

iheartbreakz, on 21 September 2012 - 06:53 PM, said:

yea i knew that but my question is wouldnt <= mean less than OR equal to?

What macosxnerd101 is saying is that your second condition will always have the same result, because it sets the value to 0. It has the same result as writing
\$this->itemCount = 0
if (\$this->itemCount)

While the first actually compares the value, which will return true or false depending on whether the value is less than or equal to 0 or greater than 0.