Skip to content

Commit

Permalink
Support for break and continue added to for and foreach. (ZeraGmbH#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
JMS-1 authored Oct 11, 2024
1 parent 4e3022a commit 2ed8b6c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Library/Core/Blocks/Controls/ControlsFor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ public class ControlsFor : Block

await statement!.EvaluateAsync(context);

if (context.EscapeMode == EscapeMode.Break) break;

context.EscapeMode = EscapeMode.None;

context.Variables[variableName] = (double)context.Variables[variableName]! + byValue;
}

context.EscapeMode = EscapeMode.None;

return await base.EvaluateAsync(context);
}
}
11 changes: 7 additions & 4 deletions Library/Core/Blocks/Controls/ControlsForEach.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ public class ControlsForEach : Block
{
context.Cancellation.ThrowIfCancellationRequested();

if (context.Variables.ContainsKey(variableName))
context.Variables[variableName] = item;
else
context.Variables.Add(variableName, item);
context.Variables[variableName] = item;

await statement.EvaluateAsync(context);

if (context.EscapeMode == EscapeMode.Break) break;

context.EscapeMode = EscapeMode.None;
}

context.EscapeMode = EscapeMode.None;

return await base.EvaluateAsync(context);
}
}

0 comments on commit 2ed8b6c

Please sign in to comment.