1: There can be one statement after a return statement but no more.
2: That one statement will still be executed.
3: If the return statement is in an if statement, then nothing after the if statement will be executed.
@Simeon This doesn’t seem right. No statements should be allowed after a return statement let alone be executed. If you try to uncomment the second text statement, it causes an error.
function draw()
background(40, 40, 50)
fill(255)
xx()
end
function xx()
return
text("statement 1 executed after a return",WIDTH/2,HEIGHT/2)
--text("statement 2 executed after a return",WIDTH/2,HEIGHT/2)
end
@dave1707, try returning a value with the return statement. For me at least, that makes the following line cause an error. I think the issue is just when return is called without anything after it, so returning nil.
function draw()
background(40, 40, 50)
fill(255)
xx()
end
function xx()
if true then
return --0
text("statement 1 executed after a return",WIDTH/2,HEIGHT/2)
end
text("statement 2 executed after a return",WIDTH/2,HEIGHT/2)
end
Maybe return can only have one thing after it, then it must be an end. I guess this makes sense as you quit the function after returning a value, so you don’t need anything after it.