Skip to content

Commit be3d9f7

Browse files
committed
correct older Java statements
1 parent d93f2ae commit be3d9f7

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

‎source/ch4_conditionals.ptx‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,13 @@ Using this operator can make code shorter and more readable in cases where a sim
318318
<p>Java requires parentheses around the condition and curly braces for code blocks in <c>if</c> statements, unlike Python which uses indentation alone.</p>
319319
</li>
320320
<li>
321-
<p>Java uses <c>else if</c> instead of Python's <c>elif</c>, and allows optional curly braces for single-line blocks.</p>
321+
<p>Java uses <c>else if</c> instead of Python's <c>elif</c>, and allows optional curly braces for single-line blocks. However, it is considered good practice to use curly braces even for single-line blocks to improve readability.</p>
322322
</li>
323323
<li>
324-
<p>Java includes a <c>switch</c> statement for checking equality against constant values, which can replace long <c>if-else</c> chains for specific scenarios.</p>
324+
<p>
325+
Java's <c>switch</c> statement is similar to Python's <c>match</c> statement, but it only supports equality checks against constant values and does not evaluate relational expressions like greater than or less than.
326+
</p>
327+
325328
</li>
326329
<li>
327330
<p>
@@ -408,17 +411,17 @@ Using this operator can make code shorter and more readable in cases where a sim
408411
</choice>
409412
</choices>
410413
</exercise>
411-
<exercise label="summary-switch">
414+
<exercise label="summary-switch-limitation">
412415
<statement>
413-
<p>What is one limitation of Java's <c>switch</c> statement?</p>
416+
<p>What is one limitation of Java's <c>switch</c> statement, including in its modern versions?</p>
414417
</statement>
415418
<choices>
416419
<choice>
417420
<statement>
418421
<p>It cannot evaluate relational expressions like greater than or less than.</p>
419422
</statement>
420423
<feedback>
421-
<p>No, while <c>switch</c> can compare values, it does not support relational expressions like <c>&gt;</c> or <c>&lt;</c>.</p>
424+
<p>No, while <c>switch</c> can compare values, it does not support relational expressions like <c>&gt;</c> or <c>&lt;</c>, even with modern enhancements of Java 14+</p>
422425
</feedback>
423426
</choice>
424427
<choice>
@@ -431,10 +434,10 @@ Using this operator can make code shorter and more readable in cases where a sim
431434
</choice>
432435
<choice>
433436
<statement>
434-
<p>It allows fall-through behavior when <c>break</c> is omitted.</p>
437+
<p>It always requires a <c>break</c> statement.</p>
435438
</statement>
436439
<feedback>
437-
<p>Incorrect. This is actually a feature of <c>switch</c>, not a limitation.</p>
440+
<p>Incorrect. The <c>break</c> statement is actually an optional feature of <c>switch</c>, not a limitation.</p>
438441
</feedback>
439442
</choice>
440443
<choice correct="yes">

0 commit comments

Comments
 (0)