Skip to content

Commit 72896c9

Browse files
committed
clarifications of match-case
1 parent e35c6b3 commit 72896c9

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

source/ch4_conditionals.ptx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ public class ElseIf {
162162
<title>Using the <c>switch</c> Statement</title>
163163

164164
<p>
165-
Java also supports a <c>switch</c> statement that acts something like the <c>elif</c> statement of Python under certain conditions. To write the grade program using a <c>switch</c> statement we would use the following:
165+
Java also supports a <c>switch</c> statement that acts something like the <c>elif</c> or Python <c>match</c> statement of Python under certain conditions. To write the grade program using a <c>switch</c> statement we would use the following:
166166
</p>
167167

168168
<note>
169169
<p>
170-
Depending on your knowledge and experience with Python you may be questioning why we are not using the <c>match</c> statement in our Python examples. The answer is that this book currently runs its active code examples using Python 3.7, which does not support the <c>match</c> statement which was introduced in Python 3.10. Below is an example of the <c>match</c> statement similar to our grade method.
170+
The <c>match - case</c> statement was introduced in Python 3.10, so doesn't run in earlier version of Python. Here is an example using Python's <c>match - case</c> structure.
171171
</p>
172172
<program xml:id="python-match" language="python">
173173
<title>Match Case Example</title>
@@ -192,7 +192,7 @@ Java also supports a <c>switch</c> statement that acts something like the <c>eli
192192
</note>
193193

194194
<p><idx><c>switch</c></idx>
195-
The <c>switch</c> statement in Java provides a clean and efficient alternative to chaining multiple <c>if-else</c> conditions, especially when comparing a single variable against several constant values. It supports a variety of data types, including primitive types (<c>byte</c>, <c>short</c>, <c>char</c>, <c>int</c>), their wrapper classes, <c>enumerations</c>, and <c>String</c> (introduced in Java 7). Each <c>case</c> within a <c>switch</c> must be defined using a constant expression, and duplicate <c>case</c> values are not permitted. By default, control flow "<c>falls through</c>" from one <c>case</c> to the next unless a <c>break</c>, <c>return</c>, or <c>throw</c> statement is used to terminate execution.
195+
The <c>switch</c> statement in Java provides an alternative to chaining multiple <c>if-else</c> conditions, when comparing a single variable against several constant values. It supports a variety of data types, including primitive types (<c>byte</c>, <c>short</c>, <c>char</c>, <c>int</c>), their wrapper classes, <c>enumerations</c>, and <c>String</c> (introduced in Java 7). Each <c>case</c> within a <c>switch</c> must be defined using a constant expression, and duplicate <c>case</c> values are not permitted. By default, control flow "<c>falls through</c>" from one <c>case</c> to the next unless a <c>break</c>, <c>return</c>, or <c>throw</c> statement is used to terminate execution.
196196
</p>
197197

198198
<p>

0 commit comments

Comments
 (0)