Skip to content

Commit 6e452dc

Browse files
committed
add listing
1 parent 3ac8b5d commit 6e452dc

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

source/ch4_conditionals.ptx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@
1616
In Python the simple <c>if</c> statement is written as:
1717
</p>
1818

19-
<program xml:id="python-simple-if" interactive="activecode" language="python">
19+
<listing xml:id="python-simple-if">
20+
<program interactive="activecode" language="python">
2021
<code>
2122
score = 95
2223
if score &gt;= 90:
2324
print("Excellent work!")
2425
</code>
2526
</program>
27+
</listing>
28+
2629
<p>
2730
In Java, this same pattern requires two changes: the condition must be in parentheses <c>()</c>, and the code block must be enclosed in curly braces <c>{}</c>.
2831
</p>
29-
<program xml:id="java-simple-if" interactive="activecode" language="java">
32+
<listing xml:id="java-simple-if">
33+
<program interactive="activecode" language="java">
3034
<code>
3135
public class SimpleIfExample {
3236
public static void main(String[] args) {
@@ -38,6 +42,8 @@ if score &gt;= 90:
3842
}
3943
</code>
4044
</program>
45+
</listing>
46+
4147
<p>
4248
Once again you can see that in Java the curly braces define a block rather than indentation.
4349
In Java, the parentheses around the condition are required because it is technically a function that evaluates to <c>True</c> or <c>False</c>.

0 commit comments

Comments
 (0)