Skip to content

Commit 2b1f682

Browse files
committed
added the listing to text
1 parent 4c2a1b4 commit 2b1f682

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

source/ch4_conditionals.ptx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ The <c>switch</c> statement is not used very often, and we recommend you do not
261261
<title>Exception Handling</title>
262262

263263
<p>
264-
In Python, if you want a program to continue running when an error has occurred, you can use <c>try-except</c> blocks to handle exceptions. If you wanted to write a program that asks the user to enter a whole number and then squares that number, you could use the following code to do so:
264+
In Python, if you want a program to continue running when an error has occurred, you can use <c>try-except</c> blocks to handle exceptions. If you wanted to write a program that asks the user to enter a whole number and then squares that number, you could use the following code to do so. <xref ref="python-square-input" text="type-global"/> shows the Python code to achieve this.
265265
</p>
266266

267267
<listing xml:id="python-square-input">
@@ -275,7 +275,7 @@ The <c>switch</c> statement is not used very often, and we recommend you do not
275275
</listing>
276276

277277
<p>
278-
The Java code that would perform the same task is a little more complex and utilizes the <c>Scanner</c> class for input.
278+
<xref ref="java-square-input" text="type-global"/> shows the Java code that would perform the same task. It is a little more complex and utilizes the <c>Scanner</c> class for input.
279279
</p>
280280
<listing xml:id="java-square-input">
281281
<program interactive="activecode" language="java">
@@ -298,7 +298,7 @@ The <c>switch</c> statement is not used very often, and we recommend you do not
298298
</listing>
299299

300300
<p>
301-
This code works well, but will end with an exception if the user types anything other than a whole number (such as 12.5 or two). If we wanted to ensure the code will continue to run until the user enters the correct format, we could add <c>try-except</c> (Python) or <c>try-catch</c> (Java) blocks within a <c>while</c> loop that iterates until the user enter the correct code. Adding <c>try-except</c> blocks and a <c>while</c> loop to the Python code will look something like this:
301+
This code works well, but will end with an exception if the user types anything other than a whole number (such as 12.5 or two). If we wanted to ensure the code will continue to run until the user enters the correct format, we could add <c>try-except</c> (Python) or <c>try-catch</c> (Java) blocks within a <c>while</c> loop that iterates until the user enter the correct code. <xref ref="python-square-input-exception" text="type-global"/> shows how adding <c>try-except</c> blocks and a <c>while</c> loop to the Python code will look.
302302
</p>
303303
<listing xml:id="python-square-input-exception">
304304
<program interactive="activecode" language="python">
@@ -316,7 +316,7 @@ The <c>switch</c> statement is not used very often, and we recommend you do not
316316
</listing>
317317

318318
<p>
319-
Now that we have Python code that will continuously prompt the user until they enter a whole number, let's look at Java code that accomplishes the same task. Like most other equivalent Java code blocks, this code has a lot of extra bits that are necessary to get working code.
319+
Now that we have Python code that will continuously prompt the user until they enter a whole number, <xref ref="java-square-input-exception" text="type-global"/> shows the Java code that accomplishes the same task. Like most other equivalent Java code blocks, this code has a lot of extra bits that are necessary to get working code.
320320
</p>
321321
<listing xml:id="java-square-input-exception">
322322
<program interactive="activecode" language="java">

0 commit comments

Comments
 (0)