bcquality/microsoft/knowledge/style/no-begin-end-around-single-statement.md
Jesper Schulz-Wedde b6da405376 Improve partner onboarding and documentation navigation
Lead with a complete plugin quick start and add task-oriented usage, troubleshooting, customization, and contribution guides. Preserve the broader plugin framing, correct conflicting contract guidance, support Agents folder reviews, and align repository validation. Convert existing sample references to clickable links without changing knowledge rules.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
2026-09-09 17:25:29 +02:00

1.4 KiB

bc-version domain keywords technologies countries application-area
all
style
begin
end
single-statement
aa0013
codecop
compound
al
w1
all

Do not wrap a single statement in begin … end (CodeCop AA0013)

Description

CodeCop AA0013 flags begin … end blocks that contain exactly one statement. The compound-block syntax exists to group multiple statements as a unit; using it for a single statement adds two lines and a level of nesting without adding meaning. if IsAssemblyOutputLine then begin TestField("Order Line No.", 0); end; should be if IsAssemblyOutputLine then TestField("Order Line No.", 0); — one statement, no block. The same logic applies after else, for, while, and repeat.

Best Practice

A single statement following then, else, do, or a case label is written on its own line, indented one level, with no begin … end. Use begin … end only when there are two or more statements to group.

See sample: no-begin-end-around-single-statement.good.al.

Anti Pattern

if Cond then begin OneCall(); end; — single statement wrapped in a block. AA0013 flags it. The reviewer signal is "a begin followed by exactly one statement before its end."

See sample: no-begin-end-around-single-statement.bad.al.