Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 20, 2025

Adds control flow statements BREAK and CONTINUE to exit or skip iterations in WHILE loops, following SQL-99/T-SQL syntax.

Changes

  • Control flow via exceptions: Introduced BreakException and ContinueException that propagate through statement blocks to the enclosing loop
  • WHILE loop: Added try-catch in While.prototype.execute to handle control flow exceptions
  • BREAK/CONTINUE: Modified to throw exceptions instead of returning static values
  • BeginEnd fix: Implemented synchronous execution path (was previously non-functional), allowing control flow exceptions to propagate naturally

Example

SET @a = 0;
SET @result = 0;
WHILE @a < 10
BEGIN
    SET @a = @a + 1;
    IF @a = 8 BREAK;           -- Exits loop when @a reaches 8
    IF @a % 2 = 0 CONTINUE;    -- Skips even numbers
    SET @result = @result + @a;
END;
-- @result = 16 (sum of 1,3,5,7)

Exceptions propagate through nested BEGIN...END blocks correctly. Test suite (test/test37.js) covers simple loops, nested blocks, and edge cases.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • upload.wikimedia.org
    • Triggering command: /usr/local/bin/node /usr/local/bin/node node_modules/mocha/bin/mocha.js ./test --reporter dot --bail (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Add BREAK and CONTINUE statements with more reliable WHILE statement</issue_title>
<issue_description>Add statements like:

    SET @a = 1;
    WHILE @a < 10
    BEGIN
        IF @a = 8 BREAK;
        SET @a += 1;
        IF @a = 5 CONTINUE;
        SET @a += 1;
     END;

</issue_description>

<agent_instructions>start by making a testfile named test37.js, describe the needed behavour based on SQL-99

Then try to solve it. </agent_instructions>

Comments on the Issue (you are @copilot in this section)

@mathiasrw Has this been resolved?

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 20, 2025 21:55
…nsive tests

Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Copilot AI changed the title [WIP] Add BREAK and CONTINUE statements with reliable WHILE statement Implement BREAK and CONTINUE statements for WHILE loops Nov 20, 2025
Copilot AI requested a review from mathiasrw November 20, 2025 22:02
Copilot finished work on behalf of mathiasrw November 20, 2025 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add BREAK and CONTINUE statements with more reliable WHILE statement

2 participants