alguidelines/content/docs/BestPractices/unnecessary-else/index.md
Henrik Helgesen fb17dc9640 Removed Discussion Links. Using new Theme solution.
Some additional MDLint cleanup as well
2022-02-24 15:36:06 -08:00

34 lines
719 B
Markdown

---
title: "Unnecessary else"
tags: ["AL","Readability"]
categories: ["Best Practice"]
---
_Created by Microsoft, Described by waldo_
## Description
`else` should not be used when the last action in the `then` part is an `exit`, `break`, `skip`, `quit`, `error`.
## Bad code
```al
procedure SomeProcedure()
begin
if IsAdjmtBinCodeChanged() then
Error(AdjmtBinCodeChangeNotAllowedErr, ...)
else
Error(BinCodeChangeNotAllowedErr, ...);
end;
```
## Good code
```al
procedure SomeProcedure()
begin
if IsAdjmtBinCodeChanged() then
Error(AdjmtBinCodeChangeNotAllowedErr, ...)
Error(BinCodeChangeNotAllowedErr, ...);
end;
```