Your indentation suggests that several begin-end pairs are missing.
First picture:The "for" loop executes "if ((i mod 3) = 1) or (i = 9) then writeln(...)". The next instruction is NOT part of the loop although you indented it (Pascal is not Python!). (You must use "begin"/"end" pairs to enclose multiple instructions inside the loop - see below).
Therefore, your code executes only the WriteLn instructions. Then the loop is finished. It is not clear which value i has after the loop, maybe 15 or 16, certainly not 2. Therefore the condition "if i = 2" is false and the program does not jump back to L1, there is no infinite loop.
If you want to have the "goto" inside the loop you must add a begin after the "do" of the "for" loop, and an "end" after the "goto". Like this:
procedure Versuche;
label
L1;
var
i: Integer;
begin
L1:
for i := 1 to 15 do
begin
if ((i mod 3) = 1) or (i = 9) then
writeln('i was: ', i);
if i = 2 then
goto L1;
end;
end;
In this case the program jumps out of the loop back to the label L1 each time when the counter i reaches the value 2. A very bad programming technique, by the way. Shame on your teacher for even showing you something like this!
Second picture:Here again the program is behaving not as suggested by the indentation due to the missing begin/end pairs. Like before, it iterates through 15 i values in the "for" loop and prints out the "i was.." lines. After the loop we have the instruction "if i = 2 then goto L1" - but since i is not 2 after the loop the program does not jump the L1. But the next line has an unconditional goto which brings you back to the start and into the endless loop. I want to show you what your original code looks like with standard indentation:
procedure Versuche;
Label
L1;
var
i: Integer;
begin
L1:
for i := 1 to 15 do
if ((i mod 3) = 1) or (i = 9) then
writeln('i was: ', i);
if i = 2 then
writeLn('again');
goto L1;
end;
When I interpret your indentation correctly you probably mean the code to be like this:
procedure Versuche;
Label
L1:
var
i: Integer;
begin
L1:
for i := 1 to 15 do
begin
if ((i mod 3) = 1) or (i = 9) then
writeLn('i was: ', i);
if i = 2 then begin
Writeln('again');
goto L1;
end;
end;
end;