C
C
CHESS482020-01-25 18:08:36
Pascal
CHESS48, 2020-01-25 18:08:36

Goto does not work in Pascal - why?

Continuing to write the program:
Program ferma;
var a: integer;
label 1, 2;
begin
a:=187;
1: if a=1 then goto 2;
if not Odd(a) then write (a/2) else write (a*3+1);
goto 1;
2: write(a);
end.
In response, it gives an infinite number of 562 - which is the reason for the question, because, since there is goto 1 below, it must repeat the condition of line 6, that is, divide 562 by 2. Why is this, what is connected with and what to do?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2020-01-25
@GavriKos

And where do you change the contents of the variable a?

S
Stockholm Syndrome, 2020-01-25
@StockholmSyndrome

since there is goto 1 at the bottom, it must repeat the condition of line 6, that is, divide 562 by 2
firstly, not 562 by 2, but the value of the variable a, that is, 187 by 2
; secondly, well, divide so what? variable will not change its value
what to do?
to start write what you want to get in the end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question