Click to See Complete Forum and Search --> : Simple Problem - PLEASE HELP


riyaz01
04-26-2003, 03:29 PM
Can anyone tell me what the ? and : operators do in this code:

function A(s, u)
{ var t=-1, B;
text[s][f]=-1;

while( ++t <= e && text[s][f]==-1 )
{ B = t==0 ? c : (t==1 ? d : (t==2 ? b : e)); // what do the ? and : operators do?????? :(
r( s, B, u );

if ( text[s][g] > 0 )
{ text[s][f] = B; }
}
}

Many Thanks in Advance,
Riyaz01.

khalidali63
04-26-2003, 03:33 PM
var x = (n>b)?2*4 : 3+2;

the above is equivalent of
var x=0;
if(n>b){
x = 2*4;
}else{
x = 3+2;
}

Make sense......

right after the ? mark is if the statement is true after : is when the statement is false

riyaz01
04-26-2003, 03:35 PM
Much apreciated.