mP 602 - for..to loop error

Discuss about beta versions of mikroPascal compiler.
Post Reply
Author
Message
janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

mP 602 - for..to loop error

#1 Post by janni » 29 Sep 2006 15:30

Trying again :D to demonstrate disadventages of the new implementation of for... to loop, I've stumbled on an error.

Loop in the following code executes 3 times instead of expected 4

Code: Select all

  k:=2;
  j:=0;
  for i:=k shr 1 to k shl 1 do
   begin
     j:=j+2;
     if j=8 then continue;
   end;
The loop should run from i=1 to i=4 giving j=8. Unfortunately, it ends with j=6. The error is partly due to wrong implementation, because the condition intial counter value<=final value is being checked inside the loop, instead of just once at the beginning. As the compiler uses the same internal variable for initial counter value and calculations inside the loop, the result is as shown.

What I intended to do before stumbling on this error, was to show an unpleasant property of the new implementation. The following loop will run forever

Code: Select all

  for i:=1 to 4 do
   begin
     if i=4 then continue;
   end;
because the continue statement increases the counter without checking if final value was reached (exactly opposite to the explanation in help:
continue statement in for loop moves program counter to the line with keyword for; it does not change the loop counter
)

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: mP 602 - for..to loop error

#2 Post by zristic » 30 Sep 2006 11:25

We will check this. Thanks.

Post Reply

Return to “mikroPascal Beta testing”