Skip to content

Commit bc89252

Browse files
committed
add comments to 5.2
1 parent 296cd38 commit bc89252

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

source/ch5_loopsanditeration.ptx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ public class StringIterationExample {
179179
<program xml:id="python-countdown" interactive="activecode" language="python">
180180
<code>
181181
i = 5
182-
while i &gt; 0:
182+
while i &gt; 0: # while i is greater than 0
183183
print(i)
184-
i = i - 1
184+
i = i - 1 # decrement i by 1
185185
</code>
186186
</program>
187187

@@ -192,10 +192,10 @@ while i &gt; 0:
192192
<code>
193193
public class WhileLoopExample {
194194
public static void main(String[] args) {
195-
int i = 5;
196-
while (i &gt; 0) {
195+
int i = 5; // initialize i to 5
196+
while (i &gt; 0) { // while i is greater than 0
197197
System.out.println(i);
198-
i = i - 1;
198+
i = i - 1; // decrement i by 1
199199
}
200200
}
201201
}
@@ -214,10 +214,10 @@ public class WhileLoopExample {
214214
<code>
215215
public class DoWhileExample {
216216
public static void main(String[] args) {
217-
int i = 10;
218-
do {
217+
int i = 10; // initialize i to 10
218+
do { // do-while loop, will run at least once no matter the condition
219219
System.out.println("This runs once, i = " + i);
220-
} while (i &lt; 5);
220+
} while (i &lt; 5); // while i is less than 5
221221
}
222222
}
223223
</code>

0 commit comments

Comments
 (0)