Skip to content

wasm: Fix infinite loop using continue in C-like for loops - #26250

Merged
spytheman merged 2 commits into
vlang:masterfrom
SheatNoisette:wasm_fix_cfor_continues
Jan 3, 2026
Merged

spytheman merged 2 commits into
vlang:masterfrom
SheatNoisette:wasm_fix_cfor_continues

Conversation

@SheatNoisette

Copy link
Copy Markdown
Contributor

When a continue statement was executed, it jumped to the loop label, which was at the start of the loop. This skipped the increment step (for example, i += 2), causing the loop variable to never increment and creating an infinite loop.

Using the following example from the official VLang C - Like loops:

for i := 0; i < 10; i += 2 {
    // Don't print 6
    if i == 6 {
        continue
    }
    println(i)
}

Before this patch, this prints the following and goes into an infinite loop:

0
2
4

C Backend output:

0
2
4
8

@SheatNoisette

Copy link
Copy Markdown
Contributor Author

By more testing, this also resolved the infinite loop with the documentation example of labelled break & continue:

outer: for i := 4; true; i++ {
    println(i)
    for {
        if i < 7 {
            continue outer
        } else {
            break outer
        }
    }
}

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.
Thank you @SheatNoisette πŸ™‡πŸ» .

@spytheman
spytheman merged commit 8661933 into vlang:master Jan 3, 2026
74 checks passed
@SheatNoisette
SheatNoisette deleted the wasm_fix_cfor_continues branch January 3, 2026 17:34
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.

2 participants