0

Dear all,

How would you best explain the below code fragment?

return (i == 0) ? strNum : strNum.substring(i);

Thanks alot!

4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by MoZo1
0

Dear all,

How would you best explain the below code fragment?

return (i == 0) ? strNum : strNum.substring(i);

Thanks alot!

if (i==0) is true, then return strNum, otherwhile return strNum.substring(i)

0

Rewriting with if:

if (i == 0) return strNum; else return strNum.substring(i);

But the substring with the 0 parameter already returns the whole string unchanged, so it's really:

return strNum.substring(i);

And I think it's wiser to leave for the programmer that wrote the substring function to decide if it's faster to test for special values to possibly jump through the computation or it's faster to start it asap.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.