-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathgoto.xml
139 lines (129 loc) · 3.3 KB
/
goto.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 7204e2dbb9b484c8b67bb5ad4a93fa1369c5b317 Maintainer: takagi Status: ready -->
<!-- Credits: mumumu -->
<sect1 xml:id="control-structures.goto" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>goto</title>
<?phpdoc print-version-for="goto"?>
<para>
<mediaobject>
<alt>What's the worse thing that could happen if you use goto?</alt>
<imageobject>
<imagedata fileref="en/language/figures/xkcd-goto.png" format="PNG"/>
</imageobject>
<caption>
<simpara>
この画像は <link xlink:href="&url.xkcd;292">xkcd</link> から提供いただいたものです。
</simpara>
</caption>
</mediaobject>
</para>
<para>
<literal>goto</literal> 演算子を使用すると、
プログラム中の他の命令にジャンプすることができます。
ジャンプ先はラベルとコロンで表し、
<literal>goto</literal> の後にそのラベルを指定します。
ラベルは大文字小文字を <emphasis>区別します</emphasis>。
これは、完全に制約のない <literal>goto</literal> というわけではありません。
対象となるラベルは同じファイル上の同じコンテキストになければなりません。
つまり、関数やメソッドの外に飛び出したり
関数やメソッドの中に突入したりすることはできないということです。
また、いかなるループや switch 構造の中にも突入することができません。
逆にループや switch 構造から抜け出すことはできます。一般的な用法としては、
<literal>goto</literal> を複数レベルの
<literal>break</literal> として使うものがあります。
</para>
<para>
<example>
<title><literal>goto</literal> の例</title>
<programlisting role="php">
<![CDATA[
<?php
goto a;
echo 'Foo';
a:
echo 'Bar';
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Bar
]]>
</screen>
</example>
</para>
<para>
<example>
<title>ループでの <literal>goto</literal> の例</title>
<programlisting role="php">
<![CDATA[
<?php
for ($i = 0, $j = 50; $i < 100; $i++) {
while ($j--) {
if ($j == 17) {
goto end;
}
}
}
echo "i = $i";
end:
echo 'j hit 17';
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
j hit 17
]]>
</screen>
</example>
</para>
<para>
<example>
<title>これは動作しません</title>
<programlisting role="php">
<![CDATA[
<?php
goto loop;
for ($i = 0, $j = 50; $i < 100; $i++) {
while ($j--) {
loop:
}
}
echo "$i = $i";
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Fatal error: 'goto' into loop or switch statement is disallowed in
script on line 2
]]>
</screen>
</example>
</para>
</sect1>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->