Question with returns in bool

Hello guys, i have a question about "if" in one line. the idea of the function is to return the value if the sentence has or not characters. Because in if like this it works.

bool isEmpty(string s){

if (length(s)== 0){
return true;
} else {
return false;
}

But the idea is to work like this

(length(s) != 0)? return false: return true;
Last edited on
This is fine, but a simple return !length(s); is preferred.

The syntax you're looking for is
return (length(s) != 0)? false: true;
However, in a boolean context, testing against 0 is redundant:
return length(s)? false: true;
And you might as well just return the result of the test:
return !length(s);
Last edited on
Thx a lot :).
Topic archived. No new replies allowed.