# CodeCop Warning AA0205
Variables must be initialized before usage.
## Description
Always initialize a variable before usage. This can improve readability and make debugging easier.
## Reason for the rule
Using uninitialized variables may lead to strange behavior, the code may become harder to debug and in some cases readability of the code can decrease.
## Bad code example 1
```al
var
    x: Integer;
    z: Integer;

procedure Proc1()
var
begin
    Proc2(z);
    x := z;
end;

procedure Proc2(z: Integer)
var
begin
    z := 10;
end;
```
## Good code example 1
```al
var
    x: Integer;
    z: Integer;

procedure Proc1()
var
begin
    Proc2(z);
    x := z;
end;

procedure Proc2(var z: Integer)
var
begin
    z := 10;
end;
```
## Bad code example 2
```al
 procedure TestFunc()
    var
        a: Integer;
        b:​ Integer;
    begin
​        b := a + 1;
    end;
```
## Good code example 2
```al
procedure TestFunc()
    var
        a: Integer;
        b: Integer;
    begin
        a := 0;

        b := a + 1;
    end;
```
## Remarks
Variables of the following types are analyzed: Integer, BigInteger, Boolean, Byte, Char, Code, Date, DateTime, Decimal, List, Record, and Time.
Some variables need special initialization, for example, List is initialized using `.Add()`, Record is initialized via `.Init()`, `.Clear()`, or assignment. Local record variables and arrays are ignored. Global record variables can be initialized in other method.
Initialization is possible using evaluate, for, foreach statements. If a variable is passed in a method through var, the rule considers it initialized in the method.
## Related information
CodeCop Analyzer<codecop>
Get Started with AL<../devenv-get-started>
Developing Extensions<../devenv-dev-overview>

Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/analyzers/codecop-aa0205, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact. https://jonas-paprotka.de/docs/dev-itpro/developer/analyzers/codecop-aa0205/
