Skip to content

Commit a1c3cc2

Browse files
authored
Merge pull request #262 from habibasorour/issue_248_listing
Issue 248: listing added in 4.1
2 parents 5214629 + 2b3c9ef commit a1c3cc2

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

source/ch4_conditionals.ptx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,26 @@
1313

1414

1515
<p>
16-
In Python the simple <c>if</c> statement is written as:
16+
<xref ref="python-simple-if" text="type-global"/> shows how the simple <c>if</c> statement is written in Python.
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+
29+
2630
<p>
2731
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>.
32+
<xref ref="java-simple-if" text="type-global"/> shows how the simple <c>if</c> statement is written in Java.
2833
</p>
29-
<program xml:id="java-simple-if" interactive="activecode" language="java">
34+
<listing xml:id="java-simple-if">
35+
<program interactive="activecode" language="java">
3036
<code>
3137
public class SimpleIfExample {
3238
public static void main(String[] args) {
@@ -38,6 +44,8 @@ if score &gt;= 90:
3844
}
3945
</code>
4046
</program>
47+
</listing>
48+
4149
<p>
4250
Once again you can see that in Java the curly braces define a block rather than indentation.
4351
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)