Project

General

Profile

Bug #280

For loop misses first iteration in some cases.

Added by Brian Flanagan about 4 years ago. Updated about 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

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

Actions
#1

Updated by Baptiste Pillot about 4 years ago

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

Updated by Brian Flanagan about 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.

#3

Updated by Francois Lionet about 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.

#4

Updated by Brian Flanagan about 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.

Also available in: Atom PDF