- Home /
control flow of void method
update() is a void return type method. Now we are not required to type "return" statement, as the method won't return anything. But if we type it, what will happen. For example consider the code block:
if(bool a)
{
}
if(bool b)
{
}
if(bool c)
{
}
As all of them are if(no else statement), all will run one by one, If the respecting bool are true. Now consider the following modified version:
if(bool a)
{
return;
}
if(bool b)
{
return;
}
if(bool c)
{
return;
}
Return statement is here now. So if "bool a" is true, program gets the return statement on this "if" block. Now will it evaluate,
if(bool b)
{
return;
}
Or,
if(bool c)
{
return;
}
???
or return statement simply end executing a method for this frame(if it gets called by every frame.)?
Answer by perchik · Feb 21, 2014 at 07:49 PM
"Return statement is here now. So if "bool a" is true, program gets the return statement on this "if" block. Now will it evaluate," FALSE
If a is true, the return statement tells it to stop evaluating that function.
I don't know what your question is, but I don't think you quite understand how return works. When you call return in a function, it tells the system that the function is done, nothing happens after that point.
I needed the confirmation that return seals the execution of a void method too. Thanks.
Your answer
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
Power-Ups scripting error 1 Answer
Questions about the event system in unity. 1 Answer
Controlling Unity3d From Outside 3 Answers
character controll 6 Answers