views:

96

answers:

5

Hello,

I'm comparing values of an excel sheet to record values returned from a database and one record is passing through the if statement when it should fail the if statement.

The if statement looks like this:

if (record.value.equals(cellVal) == false)

    {
        record.value = cellVal
        record.modifyUser = userId
        //dataService.updateManualEntry(record)
        println "UPDATING ${record.value.equals(cellVal)}"
        println "record value: ${record.value}"                                 
        updatedCount++
        }else{
            println "NOT UPDATING [ [ ${record.value.length()} ]  + [${cellVal.length()}]"

        }

            }

The println shows that the value of println "UPDATING ${record.value.equals(cellVal)}" evaluates to be true, in which case I don't understand why it is passing through the if statement. In addition the length of the string is 0.

Can I get a second pair of eyes and figure out why a true value would get through this if statement?

+2  A: 
(true == false) ⇒ false
msw
+4  A: 

Your printlns happen after you have changed the value to match.

Carl Manaster
+3  A: 

Here:

record.value = cellVal

You have set record.value to cellVal inside the if block. That's why the println returns true.

Bytecode Ninja
+2  A: 

the println is showing true becoz of the 1st line in your if statement

record.value = cellVal

try printing the same value before if statement.

Tushar Tarkas
A: 

if ->record.value.equals(cellVal) give u false u compare (false)==false, naturally false is always = false, hence it will pass through

2nd, look at ur code,

record.value = cellVal

record.modifyUser = userId

//dataService.updateManualEntry(record)

println "UPDATING ${record.value.equals(cellVal)}"

U assign record.value = cellVal before u do a print. Of cuz it will print true.

C_Rance