The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+11 votes
790 views

Given the programming constructs

  1. assignment
  2. for loops where the loop parameter cannot be changed within the loop
  3. if-then-else
  4. forward go to
  5. arbitrary go to
  6. non-recursive procedure call
  7. recursive procedure/function call
  8. repeat loop,

which constructs will you not include in a programming language such that it should be possible to program the terminates (i.e., halting) function in the same programming language

  1. (ii), (iii), (iv)
  2. (v), (vii), (viii)
  3. (vi), (vii), (viii)
  4. (iii), (vii), (viii)

 

asked in Programming by Veteran (69k points)
edited by | 790 views
What is the difference between forward goto and arbitrary goto ?
Need further clarifications of the question, in simpler words.
Please clarify why point (ii) for loops where the loop parameter cannot be changed within the loop.............can be included.
@ arjun sir plz explain this

2 Answers

+15 votes

Ans: (B)

Arbitary goto,recursive call and repeat may enter infinite loop,and hence terminates program may not be able to answer if 'the program does terminate'.

answered by Loyal (3.9k points)
edited by
int a =5;

while (a)

{

a--;

--a;

}

here also we wont be able to terminate our program ryt ?

so answer may diifer ?
@Dexter why here program not terminate?

when we get while(0) it will terminate. rt?
can someone plz explain the option more clearly ... ?
Please explain why point (ii) for loops where the loop parameter cannot be changed within the loop.............can be included.
What is the difference between forward and arbitrary goto?
+5 votes
Eliminating options:-

Looking at the given list,7 and 8 will definitely in the answer so we can eliminate option 1 on this base.

Now we are left with 2,3,4 option.In which 2 items 7,8 are there in every option.So we just need to check 5,6,3 to get the answer.

If-else is just a block of constant set of statements,hence it cannot will not cause any looping.

Also,,Non recursive procedure call will not cause any looping in the program.

Now arbitrary goto can cause looping.Assume i have following code:-

LABEL:- statement 1

              statement 2

            GOTO LABEL. // Loop infinite

So based on this we can conclude b is the correct answer.
answered by Veteran (23.5k points)
but if arbitrary goto can cause looping?

Can u give some example?
The example in the last of my answer shows that arbitrary goto can cause loop. @srestha
how r u say it arbitrary?
arbitary means randomly which means goto can be placed anyhwere.Now someone can place it the way i did or some other way(which lead to infinite loop).

We have also selected recursion in the given answer.Now that does not mean that every recursion will stop the program from termintaion.Recursive program may or may not goto infinite loop.But as in the question,we need the program to terminate so we will not allow recursion.

Same for GOTO.Presence of GOTO means some probability(not always) of going into infinite loop as mentioned in the answer.

If i don't select goto in the answer it means that GOTO can never take program to infinite loop.But it is false statement.So GOTO should be in the answer.

Does this make sense now?
yes

but then forward goto also has an option
I have eliminated option 1 which has forward GOTO as mentioned in answer.

I am not sure by forward GOTO but as per name it means it can go in forward direction.So it cannot goto infinite loop.Becasue if it always go in forward direction then at sometime we will approach program end.Either by executing program sequentially or jumping forward.

But arbitary as i said means random so it might be possible for GOTO to go forward and backward.

P.S;- I have looked for forward goto in google but does not find any information.


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

33,593 questions
40,128 answers
114,021 comments
38,389 users