Computer Science: An Overview: Global Edition (12th Edition)

Published by Pearson Higher Education
ISBN 10: 1292061162
ISBN 13: 978-1-29206-116-0

Chapter 12 - Theory of Computation - Chapter Review Problems - Page 570: 10

Answer

See the explanation

Work Step by Step

In Bare Bones, to simulate the statement `copy name1 to name2` using a posttest loop expressed in the form `repeat...until (name equals 0)`, you can use the following code: ``` clear name2 incr name2 clear temp repeat: decr name1 incr temp until (name1 equals 0) repeat: decr temp incr name2 until (temp equals 0) ``` Explanation: - First, `clear name2` initializes `name2` to zero. - Then, `incr name2` increments `name2` by 1 to match `name1` (assuming `name1` is already initialized). - `clear temp` initializes a temporary variable `temp` to zero. - In the first `repeat` loop: - `decr name1` decrements `name1` by 1 until it equals zero. - `incr temp` increments `temp` by 1 for each decrement of `name1`, effectively storing the value of `name1`. - Once `name1` reaches zero, the loop terminates. - In the second `repeat` loop: - `decr temp` decrements `temp` by 1. - `incr name2` increments `name2` by 1 for each decrement of `temp`, effectively copying the value of `name1` to `name2`. - This loop continues until `temp` equals zero, ensuring that `name2` contains the same value as `name1`.
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.