Bug in using "continue" in nested foreach loop
Nobody has claimed this yet.
- Dominant language
- PowerShell
- Stars
- 881
- Forks
- 285
- Avg merge
- 3d 36m
- Merged PRs (30d)
- 1
Description
Please include the following with each issue:
1. Describe the bug
When using continue inside a foreach loop that resides within another loop, continue will step out of the inner foreach loop.
2. To Reproduce
Steps to reproduce the behavior:
- Go to '...'
codeunit 50000 "MyContinueTest"
{
trigger OnRun()
var
List: List of [Code[1]];
Item: Code[1];
FieldNo: Integer;
Nos: Integer;
begin
Nos := 5;
List.Add('A');
List.Add('B');
List.Add('C');
for FieldNo := 1 to Nos do begin
if FieldNo = 3 then
continue;
foreach Item in List do
if item = 'A' then
continue
else
Message('Field No: %1 Processing item: %2', FieldNo,Item);
end;
end;
}
3. Expected behavior
In the example above I would expect message boxes with Fieldnos 1 to 3 and item B and C.
4. Actual behavior
I get no Message box at all!
5. Versions:
- AL Language: 18.0.2732683
- Visual Studio Code: 1.137.0
- Business Central: 28.4
- List of Visual Studio Code extensions that you have installed: Disabled
- Operating System:
- Windows
- Linux
- MacOS
Final Checklist
Please remember to do the following:
-
Search the issue repository to ensure you are reporting a new issue
-
Reproduce the issue after disabling all extensions except the AL Language extension
-
Simplify your code around the issue to better isolate the problem
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided AL codeunit reproduction with AL Language 18.0.2732683 and Business Central 28.4, then trace how nested foreach and continue are handled by the compiler or language extension. Done means continue skips only the current foreach iteration, producing messages for items B and C in the expected outer-loop iterations.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100