Given the following programming constructs: i) assignment ii) for loops where…

1999

Given the following programming constructs:

i) assignment

ii) for loops where the loop parameter cannot be changed within the loop

iii) if-then-else

iv) forward goto

v) arbitrary goto

vi) non-recursive procedure call

vii) recursive procedure/function call

viii) repeat loop

Which constructs should not be included in a programming language so that it is possible to program the terminates (i.e., halting) function in the same programming language?

  1. A.

    (ii), (iii), (iv)

  2. B.

    (v), (vii), (viii)

  3. C.

    (vi), (vii), (viii)

  4. D.

    (iii), (v), (viii)

Attempted by 2 students.

Show answer & explanation

Correct answer: B

To make the terminates (halting) function computable for a programming language, every program in that language must have decidable termination. Bounded for loops whose loop variable cannot be changed, if-then-else, forward goto, assignments, and non-recursive procedure calls do not introduce unbounded control flow by themselves.

Arbitrary goto can jump backward and create loops. A repeat loop can execute indefinitely if its stopping condition is never met. Recursive procedure/function calls can also create unbounded computation. These are the constructs that must be excluded. Therefore, the constructs not to include are (v), (vii), and (viii), so option B is correct.

Explore the full course: Gate Guidance By Sanchit Sir