Project

General

Profile

Actions

Bug #280

closed

For loop misses first iteration in some cases.

Added by Brian Flanagan over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Target version:
Start date:
03/01/2020
Due date:
% Done:

0%

Estimated time:
Affected version:

Description

For loops should ALWAYS complete the first iteration (even if the Step is in the wrong direction), but in AOZ they don't.
(This is probably related to bug #259. I've included a similar example here.)
I'm guessing this is because the comparison is being done at the For instead of at the Next, as it should be.

In the 3 test cases shown in the following example, AOZ fails the first (and only) iteration:

#manifest:"pc"
#splashScreen:false

Print "2 To 1"
For x=2 To 1
  print x
Next x

Print "1 To 2 Step -1"
For x=1 To 2 Step -1
    Print x
Next x

Print "1 To 1"
For x=1 To 1
    Print x
Next x

Print "Done"

Results (FAIL):

2 To 1
1 To 2 Step -1
1 To 1
Done

Result SHOULD be:

2 To 1
 2
1 To 2 Step -1
 1
10 To 10
 10
Done


Related issues 1 (0 open1 closed)

Related to AOZ Studio Beta - Bug #259: For...Next from 1 to 1 doesn't enter the loopClosedFrancois Lionet02/27/2020

Actions
Actions #1

Updated by Baptiste Pillot over 4 years ago

  • Related to Bug #259: For...Next from 1 to 1 doesn't enter the loop added
Actions #2

Updated by Brian Flanagan over 4 years ago

  • Affected version changed from 0.9.5.1 to 0.9.6

1 to 1 example corrected. Other two still fail in 0.9.6.

Actions #3

Updated by Francois Lionet over 4 years ago

  • Status changed from New to Resolved
  • Assignee set to Francois Lionet
  • Target version set to 0.9.6.1

OK, tough one.

In modern languages, when a loop- has no reason to run, it is not.
In Basic, in the Amiga days, the loop was always run once.

So, the only solution here is differentiating between Amiga and PC, so in Amiga mode, the loop is always ran once, and in PC mode, if the initial values are out of range, it does not enter the loop.

Actions #4

Updated by Brian Flanagan over 4 years ago

  • Status changed from Resolved to Closed

Tested in the current version 0.9.7 test 2, and all cases work fine!

I would still recommend warning messages in the transpiler if the loop direction is wrong.

Actions

Also available in: Atom PDF