user3418286
user3418286

Reputation: 5

Check if all values are correct looping

I would like to create a looping for check table.

If one of Col3 contains "no" variable a will be filled "no"

If all values of Col3 = yes, variable a will be return value yes

Col1  depend  isResolved
im1    SD10349    yes
im2    SD10349    no
im3    SD10349    yes

I have code as below

var frel = new SCFile("screlation");
var q = "depend=\"SD10349\"";
var rc = frel.doSelect(q);
var a="";
while(rc==RC_SUCCESS){
    switch(true){
        case frel.isResolved=="yes":
            a="yes";break;
        case frel.isResolved=="no":
            a="no";break;
    }
    rc=frel.getNext();
}
print(a);

but variable a always return yes. Appreciate for anything helps :)

Regards, Okik

Upvotes: 0

Views: 58

Answers (3)

sukumar2267
sukumar2267

Reputation: 130

here problem is your not clearing the previous value. clear the previous value. after first case make the a value as null or empty.

after rc=frel.getNext(); statement clear the a variable value before going to the next loop.

a.val('');

Upvotes: 0

gurvinder372
gurvinder372

Reputation: 68393

In a switch statement, switch has the expression parameter, not the possible output of expression.

Try reversing the same

switch(frel.isResolved){ //expression as the parameter to switch
    case "yes": //check the 
        a="yes";break;
    case "no":
        a="no";break;
    default: 
      break;
 }

Or simply assign the value of frel.isResolved to a (since that is what you are doing anyways)

a = frel.isResolved;

Edit

If you want to stop as soon as a no is encountered then

while( rc == RC_SUCCESS && a != "no" )
{
    a = frel.isResolved;
    rc = frel.getNext();
}

Upvotes: 2

user9141233
user9141233

Reputation:

This should do it:

  var frel = new SCFile("screlation");
    var q = "depend=\"SD10349\"";
    var rc = frel.doSelect(q);
    var a="";
    while(rc==RC_SUCCESS){
        a = (frel.isResolved=="yes")?"yes":"no"
        if(a=="no")break;
        rc=frel.getNext();
    }
    print(a);
    }

Upvotes: 2

Related Questions