Oberon Community Platform Forum
September 23, 2017, 10:27:41 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Strange behavior in 'for' statement  (Read 4286 times)
GDC
Newbie
*
Posts: 7


« 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.
Logged
Annapurna1
Newbie
*
Posts: 3


« Reply #1 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)...
Logged
Bernhard T.
Administrator
Full Member
*****
Posts: 164


« Reply #2 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
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!