Add break/continue support to for/foreach loops and fix whileuntil EscapeMode handling
ControlsFor and ControlsForEach did not support break/continue statements. ControlsWhileUntil failed to reset EscapeMode after break, corrupting outer loop execution, and lacked break/continue support in UNTIL mode.
Changes
ControlsFor.cs & ControlsForEach.cs
- Added break/continue handling after statement evaluation
- Reset
EscapeModetoNoneafter processing flow control - For loops properly increment counter before continue
ControlsWhileUntil.cs
- Moved break check from before to after statement execution
- Added continue support for WHILE mode
- Added break/continue support for UNTIL mode (was missing)
- Both modes now reset
EscapeModeto prevent outer loop corruption
Pattern follows existing ControlsRepeatExt.cs implementation:
statement.Evaluate(context);
if (context.EscapeMode == EscapeMode.Break)
{
context.EscapeMode = EscapeMode.None;
break;
}
if (context.EscapeMode == EscapeMode.Continue)
{
context.EscapeMode = EscapeMode.None;
continue;
}
Testing
Added 8 tests covering break/continue in for, foreach, while, until loops, plus nested loop isolation.
Original prompt
This section details on the original issue you should resolve
<issue_title>Various issues with break and continue</issue_title> <issue_description>* for and foreach do not support break and continue at all - could be helpful to support these
- whileuntil does not reset the EscapeMode after Break which may corrupt execution of outer loops</issue_description>
Comments on the Issue (you are @copilot in this section)
- Fixes richorama/IronBlock#66
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.