0
I have a question about the correct use of the "goto", I made a small example that illustrates my doubt:
<?php
$valor01=10;
$valor02=8;
if($valor01 > $valor02)
{
echo "valor01 é maior que valor02<br>";
}
else
{
goto rotulo;
}
rotulo:
{
echo "valor02 é maior que valor01";
}
?>
How to ensure that the label is only implemented if the if
don’t be satisfied?
As it stands the result is as follows:
valor01 é maior que valor02
valor02 é maior que valor01
That’s possible?
The goto is not recommended, as it is difficult to understand when the project gets larger.
– Weslley C X Sardinha
http://php.net/manual/en/images/0baa1b9fae6aec55bbb73037f3016001-xkcd-goto.png
– Isac
And just put the code right into Isis, no drip. That’s what Isis is for...
– marcus
In this example of yours there is no sense to use
goto
, just make the logic inside theelse
, in fact, I don’t think I ever need to use this command, since it creates a spaghetti code.– bruno101
Fully possible is just to do a table test that you will discover the snippets of your code that will be executed. The goto command exists for historical reasons. It was widely used in the programming style of the 1960s but after that its use was execrated by all the problems it causes. In your case just put another drop after the if skipping the section under label.
– anonimo
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer that you find useful on the entire site (so accepting you will gain privilege to vote).
– Maniero
If it is still necessary, OOP, do not use the drop, create a function and call it on Else. We have evolved.. hehe
– Rogerio Santos