You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit be3d9f7
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: source/ch4_conditionals.ptx
+10-7Lines changed: 10 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -318,10 +318,13 @@ Using this operator can make code shorter and more readable in cases where a sim
318
318
<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>
319
319
</li>
320
320
<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>
322
322
</li>
323
323
<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
+
325
328
</li>
326
329
<li>
327
330
<p>
@@ -408,17 +411,17 @@ Using this operator can make code shorter and more readable in cases where a sim
408
411
</choice>
409
412
</choices>
410
413
</exercise>
411
-
<exerciselabel="summary-switch">
414
+
<exerciselabel="summary-switch-limitation">
412
415
<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>
414
417
</statement>
415
418
<choices>
416
419
<choice>
417
420
<statement>
418
421
<p>It cannot evaluate relational expressions like greater than or less than.</p>
419
422
</statement>
420
423
<feedback>
421
-
<p>No, while <c>switch</c> can compare values, it does not support relational expressions like <c>></c> or <c><</c>.</p>
424
+
<p>No, while <c>switch</c> can compare values, it does not support relational expressions like <c>></c> or <c><</c>, even with modern enhancements of Java 14+</p>
422
425
</feedback>
423
426
</choice>
424
427
<choice>
@@ -431,10 +434,10 @@ Using this operator can make code shorter and more readable in cases where a sim
431
434
</choice>
432
435
<choice>
433
436
<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>
435
438
</statement>
436
439
<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>
0 commit comments