Skip to content

Commit fb10ae7

Browse files
authored
Merge pull request #292 from habibasorour/issue_288_list
Issue 288 fixed: 5.2 listing added
2 parents 7528344 + 69e453b commit fb10ae7

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

source/ch5_loopsanditeration.ptx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,21 +174,24 @@ public class StringIterationExample {
174174

175175
<p><idx><c>while</c> loop</idx>
176176
Both Python and Java support the <c>while</c> loop, which continues to execute as long as a condition is true.
177-
Here is a simple example in Python that counts down from 5:
177+
<xref ref="python-countdown" text="type-global"/> shows a simple example in Python that counts down from 5.
178178
</p>
179-
<program xml:id="python-countdown" interactive="activecode" language="python">
179+
<listing xml:id="python-countdown">
180+
<program interactive="activecode" language="python">
180181
<code>
181182
i = 5
182183
while i &gt; 0:
183184
print(i)
184185
i = i - 1
185186
</code>
186187
</program>
188+
</listing>
187189

188190
<p>
189-
In Java, we add parentheses and curly braces. Here is the same countdown loop in Java:
191+
In Java, we add parentheses and curly braces. <xref ref="java-countdown" text="type-global"/> shows the same countdown loop in Java.
190192
</p>
191-
<program xml:id="java-countdown" interactive="activecode" language="java">
193+
<listing xml:id="java-countdown">
194+
<program interactive="activecode" language="java">
192195
<code>
193196
public class WhileLoopExample {
194197
public static void main(String[] args) {
@@ -201,16 +204,17 @@ public class WhileLoopExample {
201204
}
202205
</code>
203206
</program>
207+
</listing>
204208

205209
<p><idx><c>do-while</c> loop</idx>
206210
Java adds an additional, if seldom used variation of the <c>while</c> loop called the <c>do-while</c> loop.
207211
The <c>do-while</c> loop is very similar to <c>while</c> except that the condition is evaluated at the end of the loop rather than the beginning.
208212
This ensures that a loop will be executed at least one time.
209213
Some programmers prefer this loop in some situations because it avoids an additional assignment prior to the loop.
210-
For example, the following loop will execute once even though the condition is initially false.
214+
For example, <xref ref="java-do-while" text="type-global"/> shows how loop will execute once even though the condition is initially false.
211215
</p>
212-
213-
<program xml:id="java-do-while" interactive="activecode" language="java">
216+
<listing xml:id="java-do-while">
217+
<program interactive="activecode" language="java">
214218
<code>
215219
public class DoWhileExample {
216220
public static void main(String[] args) {
@@ -222,6 +226,8 @@ public class DoWhileExample {
222226
}
223227
</code>
224228
</program>
229+
</listing>
230+
225231
</section>
226232
<section xml:id="chapter5_summary">
227233
<title>Summary &amp; Reading Questions</title>

0 commit comments

Comments
 (0)