1717
1818 <program xml : id =" python-definite-loop" interactive =" activecode" language =" python" >
1919 <code >
20- for i in range(10):
20+ for i in range(10): # range(10) is a list of integers from 0 to 9
2121 print(i)
2222 </code >
2323 </program >
@@ -30,7 +30,7 @@ for i in range(10):
3030 <code >
3131public class DefiniteLoopExample {
3232 public static void main(String[] args) {
33- for (Integer i = 0; i < 10; i++ ) {
33+ for (Integer i = 0; i < 10; i++ ) { // notice how the initialization, condition, and update are all on the same line.
3434 System.out.println(i);
3535 }
3636 }
@@ -67,7 +67,7 @@ public class DefiniteLoopExample {
6767
6868 <program xml : id =" python-deinite-decrement" interactive =" activecode" language =" python" >
6969 <code >
70- for i in range(100, -1, -5):
70+ for i in range(100, -1, -5): # start at 100, stop at 0, decrement by 5
7171 print(i)
7272 </code >
7373 </program >
@@ -80,7 +80,7 @@ for i in range(100, -1, -5):
8080 <code >
8181public class DefiniteLoopBackward {
8282 public static void main(String[] args) {
83- for (Integer i = 100; i > = 0; i -= 5) {
83+ for (Integer i = 100; i > = 0; i -= 5) { // start at 100, stop at 0, decrement by 5
8484 System.out.println(i);
8585 }
8686 }
@@ -99,8 +99,8 @@ public class DefiniteLoopBackward {
9999
100100 <program xml : id =" python-list-iteration" interactive =" activecode" language =" python" >
101101 <code >
102- l = [1, 1, 2, 3, 5, 8, 13, 21]
103- for fib in l:
102+ l = [1, 1, 2, 3, 5, 8, 13, 21] # create a list of integers
103+ for fib in l: # iterate over the list
104104 print(fib)
105105 </code >
106106 </program >
@@ -115,16 +115,16 @@ import java.util.ArrayList;
115115
116116public class ForEachArrayListExample {
117117 public static void main(String[] args) {
118- ArrayList< Integer> l = new ArrayList< Integer > ();
119- l.add(1);
120- l.add(1);
121- l.add(2);
118+ ArrayList< Integer> l = new ArrayList< // create an ArrayList of integers
119+ l.add(1); // add the first integer to the list
120+ l.add(1); // add the second integer to the list
121+ l.add(2); // keep going
122122 l.add(3);
123123 l.add(5);
124124 l.add(8);
125125 l.add(13);
126- l.add(21);
127- for (Integer i : l) {
126+ l.add(21); // add the last integer to the list
127+ for (Integer i : l) { // iterate over the list
128128 System.out.println(i);
129129 }
130130 }
@@ -141,8 +141,8 @@ public class ForEachArrayListExample {
141141 <code >
142142public class ForEachArrayExample {
143143 public static void main(String[] args) {
144- int l[] = {1,1,2,3,5,8,13,21};
145- for(int i : l) {
144+ int l[] = {1,1,2,3,5,8,13,21}; // create an array of integers using primitive syntax
145+ for(int i : l) { // iterate over the array
146146 System.out.println(i);
147147 }
148148 }
@@ -158,8 +158,8 @@ public class ForEachArrayExample {
158158 <code >
159159public class StringIterationExample {
160160 public static void main(String[] args) {
161- String t = "Hello World";
162- for (char c : t.toCharArray()) {
161+ String t = "Hello World"; // create a string
162+ for (char c : t.toCharArray()) { // iterate over the characters in the string
163163 System.out.println(c);
164164 }
165165 }
@@ -179,7 +179,7 @@ public class StringIterationExample {
179179 <program xml : id =" python-countdown" interactive =" activecode" language =" python" >
180180 <code >
181181i = 5
182- while i > 0:
182+ while i > 0:
183183 print(i)
184184 i = i - 1
185185 </code >
0 commit comments