B4J Question What's wrong with this If statement?

B4JExplorer

Active Member
Licensed User
Longtime User
Never mind, the following. I didn't realize that there was a RETURN in front. If this post can be removed, please do so, thanks.

B4X:
	Return If True Then Return "true" Else Return "false"

According to https://www.b4x.com/b4j/help/core.html#keywords_if

, a single line if, doesn't require an End If. But this returns an error, that an "end if" is missing.



If I put the End If at the end


B4X:
	Return If True Then Return "true" Else Return "false" End If

, then it just returns a generic syntax error.
 

stevel05

Expert
Licensed User
Longtime User
It seems to me that the Return at the beginning of the line would cause a syntax error as the If statement it is not a ternary operator.

B4X:
If True Then Return "true" Else Return "false"

Would be enough. Or simpler :

B4X:
If True Then Return "true"
Return "false"

You don't really need an else either.

Edit: Although If True would always execute that part.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
You cannot start with the return and follow it with the if statement...
What exactly are you trying to do?
If you want to condition your return value then you need a multiline if statement like
If a =true then
Return false
Else
Return true
End if
 
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
Cableguy and stevel05, thanks but

Note at the top of the post, the quote

"Never mind, the following. I didn't realize that there was a RETURN in front. If this post can be removed, please do so, thanks."

I realized the RETURN was in front, soon after posting the question, and then edited it. I'd prefer to remove the thread altogether, but there doesn't seem to be such an option.
 
Upvote 0
Top