|
4 | 4 | <chapter xml:id="conditionals"> |
5 | 5 | <title>Conditionals</title> |
6 | 6 |
|
7 | | - <section xml:id="simple-if"> |
8 | | - <title>Using the Simple <c>if</c> Statement</title> |
| 7 | + <section xml:id="using-conditional-in-java"> <title>Using Conditional Statements in Java</title> |
9 | 8 | <p><idx>conditional statements</idx> |
10 | 9 | Conditional statements in Python and Java are very similar. |
11 | 10 | In Python we have three patterns: |
@@ -50,9 +49,9 @@ if score >= 90: # Note the colon at the end of the line |
50 | 49 | Once again you can see that in Java the curly braces define a block rather than indentation. |
51 | 50 | 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>. |
52 | 51 | </p> |
53 | | - </section> |
| 52 | + |
54 | 53 |
|
55 | | - <section xml:id="use-the-if-else-statement"> |
| 54 | + <subsection xml:id="use-the-if-else-statement"> |
56 | 55 | <title>Using the <c>if</c> - <c>else</c> Statement</title> |
57 | 56 |
|
58 | 57 | <p><xref ref= "python-if-else" text="type-global"/> shows how the <c>if</c> - <c>else</c>statement is written in Python.</p> |
@@ -85,9 +84,9 @@ if score >= 90: # Note the colon at the end of the line |
85 | 84 | </code> |
86 | 85 | </program> |
87 | 86 | </listing> |
88 | | - </section> |
| 87 | + </subsection> |
89 | 88 |
|
90 | | - <section xml:id="elif"> |
| 89 | + <subsection xml:id="elif"> |
91 | 90 | <title>Can we use <c>elif</c>?</title> |
92 | 91 |
|
93 | 92 | <p><idx><c>elif</c> statement</idx> |
@@ -172,9 +171,9 @@ public class ElseIf { |
172 | 171 | </code> <tests> </tests> |
173 | 172 | </program> |
174 | 173 | </listing> |
175 | | - </section> |
| 174 | + </subsection> |
176 | 175 |
|
177 | | - <section xml:id="switch"> |
| 176 | + <subsection xml:id="switch"> |
178 | 177 | <title>Using the <c>switch</c> Statement</title> |
179 | 178 |
|
180 | 179 | <p> |
@@ -255,6 +254,7 @@ The <c>switch</c> statement is not used very often, and we recommend you do not |
255 | 254 | </p> |
256 | 255 | <p> |
257 | 256 | Finally, the <c>switch</c> statement does not support relational expressions such as greater than or less than. So you cannot use it to completely replace the <c>elif</c>. Even with the new features of Java 14+ the <c>switch</c> statement is still limited to constant comparisons using equality.</p> |
| 257 | + </subsection> |
258 | 258 | </section> |
259 | 259 |
|
260 | 260 | <section xml:id="exception-handling"> |
|
0 commit comments