-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathwhile.xml
More file actions
94 lines (89 loc) · 2.65 KB
/
while.xml
File metadata and controls
94 lines (89 loc) · 2.65 KB
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
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 7104ee97ced1768a3231588dfc0bc0d7eb1117ad Maintainer: takagi Status: ready -->
<sect1 xml:id="control-structures.while" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>while</title>
<?phpdoc print-version-for="while"?>
<para>
<literal>while</literal>ループは、PHPで最も簡単なタイプのループです。
このループは、CのWHILEループと同様の動作をします。
<literal>while</literal>ループの基本形は次のようになります。
<informalexample>
<programlisting>
<![CDATA[
while (式)
文
]]>
</programlisting>
</informalexample>
</para>
<simpara>
<literal>while</literal>文の意味は簡単です。
<literal>while</literal>文は、式の値が&true;である間、
入れ子の文を繰り返し実行することをPHPに指示します。
式の値は各反復処理の開始時にチェックされるので、ループ内の文の実行により
この値が変わった場合でもループ実行は各ループを終るまで終わりません。
(PHPによるループ内の文の実行が1回分の反復に相当します)
<literal>while</literal>式の値がはじめから&false;の
場合は、内部の文は一回も実行されません。
</simpara>
<para>
<literal>if</literal>文と同様に、波括弧で複数の文を囲うか、
以下に示す別の構文を用いることにより、同じ<literal>while</literal>
ループの中に複数の文をグループ化することができます。
<informalexample>
<programlisting>
<![CDATA[
while (式):
文
...
endwhile;
]]>
</programlisting>
</informalexample>
</para>
<para>
次の例は同じです。どちらも 1 から 10 までの数を出力します。
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
/* 例 1 */
$i = 1;
while ($i <= 10) {
echo $i++; /* 出力される値は、足される前の
$iの値です。
(後置加算) */
}
/* 例 2 */
$i = 1;
while ($i <= 10):
echo $i;
$i++;
endwhile;
?>
]]>
</programlisting>
</informalexample>
</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
-->