From 6676521c23ff5605caefa27250d5f646a05499df Mon Sep 17 00:00:00 2001 From: Rasmus Lerdorf Date: Sat, 20 Jun 2009 18:07:12 +0000 Subject: [PATCH] Improve goto description and add a couple of examples. Remove the warning because I think it is better to simply describe that restriction up front. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@282476 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/control-structures/goto.xml | 66 ++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 8 deletions(-) diff --git a/language/control-structures/goto.xml b/language/control-structures/goto.xml index 773a82dfe3..68f930ce53 100644 --- a/language/control-structures/goto.xml +++ b/language/control-structures/goto.xml @@ -1,5 +1,5 @@ - + <literal>goto</literal> @@ -7,7 +7,13 @@ The goto operator can be used to jump to another section in the program. The target point is specified by a label followed by a colon, and the instruction is given as - goto followed by the desired target label. + goto followed by the desired target label. This + is not a full unrestricted goto. The target + label must be within the same context, meaning that you cannot jump + out of a function or method, nor can you jump into one. You also + cannot jump into any sort of loop or switch structure. You may jump + out of these, and a common use is to use a goto + in place of a multi-level break. @@ -27,6 +33,56 @@ echo 'Bar'; + + + + + + <literal>goto</literal> loop example + + +]]> + + &example.outputs; + + + + + + + + This will not work + + +]]> + + &example.outputs; + + @@ -36,12 +92,6 @@ Bar The goto operator is available as of PHP 5.3. - - - It is not allowed to jump into a loop or switch statement. A fatal - error is issued in such cases. - -