tags:

views:

120

answers:

6

Wow...I've never seen this before. Any way to get around it?

foreach( double r in portfolioReturns)
        {
            if (-8.0 < r < -7.0)
            {
                n8++;
            }}
+5  A: 
if (-8.0 < r && r < -7.0)
Joel Coehoorn
+1  A: 
if (-8.0 < r && r < -7.0)
anthony
+1  A: 
foreach(double r in portfolioReturns)
{
    if(-8.0 < r && r < -7.0)
            n8++;
}
Justin Niessner
+3  A: 

let me guess, you are coming from python? It is the only language I know of where that works :-)

looking at (-8.0 < r < -7.0), first, -8.0 < r gets evaluated, which is true. true < -7.0 barfs.

Matt Briggs
+8  A: 

You are effectively doing this

if ((-8.0 < r) < -7.0)

Since (-8.0 < r) evaluates to a boolean, you can't compare it to a float. Do this instead:

if (-8.0 < r && r < -7.0) {
  //code here
}
Mahmoud
+3  A: 

You could also use LINQ, in addition to the fix everyone so quickly provided

n8 += portfolioReturns.Count(r => -8.0 < r && r < -7.0);
Yuriy Faktorovich