Skip to content

post-condition-loop

Rubysuspiciousno fixdefault: offruby/rubocop

Reports begin ... end while cond and begin ... end until cond.

This loop runs the body once before it tests the condition, unlike every other while or until, and readers expect the test first. loop do ... break if ... end says what happens.

To fix, write loop do, with break unless cond at the end of the body.

Reported
...
f == 0
begin
x
end while y
case x
...
when 2 then z
...
ruby:
lint:
rules:
post-condition-loop: warn # off (default), warn, error

Enabled by the presets: ruby/rubocop.

Suppress one line with sudsy-disable-next-line post-condition-loop in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
rubocop Lint/Loop full