-
-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathfor.xml
More file actions
executable file
·143 lines (110 loc) · 3.76 KB
/
Copy pathfor.xml
File metadata and controls
executable file
·143 lines (110 loc) · 3.76 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
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
140
141
142
143
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<name>for</name>
<category>Control</category>
<subcategory>Iteration</subcategory>
<usage>Web & Application</usage>
<example>
<image>for_0.png</image>
<code><![CDATA[
for (int i = 0; i < 40; i = i+1) {
line(30, i, 80, i);
}
]]></code>
</example>
<example>
<image>for_1.png</image>
<code><![CDATA[
for (int i = 0; i < 80; i = i+5) {
line(30, i, 80, i);
}
]]></code>
</example>
<example>
<image>for_2.png</image>
<code><![CDATA[
for (int i = 40; i < 80; i = i+5) {
line(30, i, 80, i);
}
]]></code>
</example>
<example>
<image>for_3.png</image>
<code><![CDATA[
// Nested for() loops can be used to
// generate two-dimensional patterns
for (int i = 30; i < 80; i = i+5) {
for (int j = 0; j < 80; j = j+5) {
point(i, j);
}
}
]]></code>
</example>
<example>
<code><![CDATA[
// This example has no visual output,
// but prints values to the console.
int[] nums = { 5, 4, 3, 2, 1 };
for (int i : nums) {
println(i);
}
]]></code>
</example>
<description><![CDATA[
Controls a sequence of repetitions. A basic <b>for</b> structure has three parts: <b>init</b>, <b>test</b>, and <b>update</b>. Each part must be separated by a semicolon (;). The loop continues until the <b>test</b> evaluates to <b>false</b>. When a <b>for</b> structure is executed, the following sequence of events occurs:<br />
<br />
1. The init statement is run.<br />
2. The test is evaluated to be true or false.<br />
3. If the test is <em>true</em>, jump to step 4. If the test is <em>false</em>, jump to step 6.<br />
4. Run the statements within the block.<br />
5. Run the update statement and jump to step 2.<br />
6. Exit the loop.<br />
<br />
In the first example above, the <b>for</b> structure is executed 40 times. In the init statement, the value <em>i</em> is created and set to zero. <em>i</em> is less than 40, so the test evaluates as <em>true</em>. At the end of each loop, <em>i</em> is incremented by one. On the 41st execution, the test is evaluated as <em>false</em>, because <em>i</em> is then equal to 40, so <em>i < 40</em> is no longer true. Thus, the loop exits.<br />
<br />
A second type of <b>for</b> structure makes it easier to iterate over each element of an array. The last example above shows how it works. Within the parentheses, first define the datatype of the array, then define a variable name. This variable name will be assigned to each element of the array in turn as the <b>for</b> moves through the entire array. Finally, after the colon, define the array name to be used.
]]></description>
<syntax>
for (<c>init</c>; <c>test</c>; <c>update</c>) {
<c>statements</c>
}
for (<c>datatype</c> <c>element</c> : <c>array</c>) {
<c>statements</c>
}
</syntax>
<parameter>
<label>init</label>
<description><![CDATA[statement executed once when beginning loop]]></description>
</parameter>
<parameter>
<label>test</label>
<description><![CDATA[if the test evaluates to <em>true</em>, the statements execute]]></description>
</parameter>
<parameter>
<label>update</label>
<description><![CDATA[executes at the end of each iteration]]></description>
</parameter>
<parameter>
<label>statements</label>
<description><![CDATA[collection of statements executed each time through the loop]]></description>
</parameter>
<parameter>
<label>datatype</label>
<description><![CDATA[datatype of elements in the array]]></description>
</parameter>
<parameter>
<label>element</label>
<description><![CDATA[temporary name to use for each element of the array]]></description>
</parameter>
<parameter>
<label>array</label>
<description><![CDATA[name of the array to iterate through]]></description>
</parameter>
<returns></returns>
<related>
while
</related>
<availability>1.0</availability>
<type>Structure</type>
<partof>PDE</partof>
</root>