Skip to content

Fix do while continue stmt#160

Open
lucic71 wants to merge 1 commit into
Cpp2Rust:masterfrom
lucic71:do-while-continue
Open

Fix do while continue stmt#160
lucic71 wants to merge 1 commit into
Cpp2Rust:masterfrom
lucic71:do-while-continue

Conversation

@lucic71
Copy link
Copy Markdown
Contributor

@lucic71 lucic71 commented May 29, 2026

A continue statement inside a do while breakes the iteration and re-evaluates the condition.

Our previous translation, i.e.

loop {
  ...
  if !cond {
    break
  }
}

never re-evaluated the condition after a continue, resulting in an infinite loop.

To fix this, use while instead of loop. This ensures that the condition is re-evaluated right after the continue:

let mut __do_while = true;
while __do_while || cond {
  __do_while = false;
  ...
}

__do_while makes sure that the first iteration of the loop is always executed.

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.

1 participant