An or operator in a return?

  • A+
Category:Languages

I just saw something like:

return (m(s1 + 1, s2) || m(s1 + 1, s2 + 1)); 

What does the || mean in a return statement? Here, m is a function; s1 and s2 are strings.

 


The line return (m(s1 + 1, s2) || m(s1 + 1, s2 + 1)); can be rewritten in this form:

if ( m(s1 + 1, s2) ) {      /* if left part not null, return 1, without         evaluationg the right part */     return 1; } else if ( m(s1 + 1, s2 + 1) ) {       /* if left was 0, test right part */     return 1; } else {      /* if both are null, return 0*/     return 0; } 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: