Oberon Community Platform Forum

Development => ETH Zonnon => Topic started by: GDC on November 06, 2010, 02:35:07 PM



Title: Strange behavior in 'for' statement
Post by: GDC on November 06, 2010, 02:35:07 PM
Hello,

The following code causes a runaway loop at runtime:
Code:
module Main;
var
 i, j: integer;
begin
 j := 10;
 for i := 1 to j do
  writeln("i =":3,i:2,"j =":5,j:2);
  inc(j)
 end;
 readln
end Main.

The Zonnon Language Report defines the for statement as follows:

The statement
  for v := low to high by step do statements end
is equivalent to
  v := low; temp := high;
  if step > 0 then
  while v <= temp do statements; v := v + step end
  else
  while v >= temp do statements; v := v + step end
  end

This definition implies that the high value is determined once before executing the loop and stored in 'temp'. The control variable (v) is checked against 'temp' to determine when to terminate the loop.  Whatever happens to any variable that took part in determining the high value should not impact the termination of the loop.


Title: Re: Strange behavior in 'for' statement
Post by: Annapurna1 on November 10, 2013, 02:46:51 AM
simply delete the line that says "inc(j);" (unlike C#..for- loops in zonnon automatically increment the control variable)...


Title: Re: Strange behavior in 'for' statement
Post by: Bernhard T. on April 04, 2014, 08:27:29 AM
simply delete the line that says "inc(j);" (unlike C#..for- loops in zonnon automatically increment the control variable)...

but dropping that line does not solve the claimed behaviour of the compiler.
This appears to be a test case for the Compiler.
--
  Bernhard