What is going wrong with this else inside a method here?
What is going wrong with this else inside a method here?
9 Replies
Your if ends with a semicolon
i was gonna make him hunt for it, but yes
oh i didnt even know that was a thing
thank you haha
Oh, I ruined
but yeah, what happens is that now you have an if statement with nothing in it because the semicolon ends it
i have another question?
in my code u can see that in the if statement i have to return 0 cause all paths have to return something. is there a way to return nothing in one path and have the other path return something instead?
no, if your method returns something it has to return something no matter what
the only other option is to throw an exception which you should only do if something unrecoverable happened
ooo ok thank you, im just used to python is all
gotcha thanks!!
the closest thing to making it return "nothing" would be to make the return type
int?
which would let you return null
which might be what you need depending on what meanings you need the return value to have