language/control-structures/goto.xml
890a03076b2708f65ff15fec9968ad6580131b36
...
...
@@ -2,11 +2,24 @@
2
2
<!-- $Revision$ -->
3
3

4
4
<sect1 xml:id="control-structures.goto" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5
-
<title><literal>goto</literal></title>
5
+
<title>goto</title>
6
6
<?phpdoc print-version-for="goto"?>
7
7
<para>
8
+
<mediaobject>
9
+
<alt>What's the worse thing that could happen if you use goto?</alt>
10
+
<imageobject>
11
+
<imagedata fileref="en/language/figures/xkcd-goto.png" format="PNG"/>
12
+
</imageobject>
13
+
<caption>
14
+
<para>
15
+
Image courtesy of <link xlink:href="&url.xkcd;292">xkcd</link>
16
+
</para>
17
+
</caption>
18
+
</mediaobject>
19
+
</para>
20
+
<para>
8
21
The <literal>goto</literal> operator can be used to jump to another
9
-
section in the program. The target point is specified by a label
22
+
section in the program. The target point is specified by a <emphasis>case-sensitive</emphasis> label
10
23
followed by a colon, and the instruction is given as
11
24
<literal>goto</literal> followed by the desired target label. This
12
25
is not a full unrestricted <literal>goto</literal>. The target
...
...
@@ -22,11 +35,13 @@
22
35
<programlisting role="php">
23
36
<![CDATA[
24
37
<?php
38
+

25
39
goto a;
26
40
echo 'Foo';
27
41

28
42
a:
29
43
echo 'Bar';
44
+

30
45
?>
31
46
]]>
32
47
</programlisting>
...
...
@@ -44,14 +59,18 @@ Bar
44
59
<programlisting role="php">
45
60
<![CDATA[
46
61
<?php
47
-
for($i=0,$j=50; $i<100; $i++) {
48
-
while($j--) {
49
-
if($j==17) goto end;
50
-
}
62
+

63
+
for ($i = 0, $j = 50; $i < 100; $i++) {
64
+
while ($j--) {
65
+
if ($j == 17) {
66
+
goto end;
67
+
}
68
+
}
51
69
}
52
70
echo "i = $i";
53
71
end:
54
72
echo 'j hit 17';
73
+

55
74
?>
56
75
]]>
57
76
</programlisting>
...
...
@@ -69,13 +88,15 @@ j hit 17
69
88
<programlisting role="php">
70
89
<![CDATA[
71
90
<?php
91
+

72
92
goto loop;
73
-
for($i=0,$j=50; $i<100; $i++) {
74
-
while($j--) {
75
-
loop:
76
-
}
93
+
for ($i = 0, $j = 50; $i < 100; $i++) {
94
+
while ($j--) {
95
+
loop:
96
+
}
77
97
}
78
98
echo "$i = $i";
99
+

79
100
?>
80
101
]]>
81
102
</programlisting>
...
...
@@ -88,20 +109,7 @@ script on line 2
88
109
</screen>
89
110
</example>
90
111
</para>
91
-
<note>
92
-
<para>
93
-
The <literal>goto</literal> operator is available as of PHP 5.3.
94
-
</para>
95
-
</note>
96
-
<para>
97
-
<mediaobject>
98
-
<alt>What's the worse thing that could happen if you use goto?</alt>
99
-
<imageobject>
100
-
<imagedata fileref="en/language/figures/xkcd-goto.png" format="PNG"/>
101
-
</imageobject>
102
-
</mediaobject>
103
-
Image courtesy of <link xlink:href="&url.xkcd;292">xkcd</link>
104
-
</para>
112
+

105
113
</sect1>
106
114

107
115
<!-- Keep this comment at the end of the file
108
116