Yes correct inside the if end!
Else it would be unregistered at first ever called addon (must not be yours e.g.) and your code would never be executed properly.
EVENT_ADD_ON_LOADED will be run once for EACH addon AND library in your live/AddOns folder.
Means it will be called for e.g LibAddonMenu-2.0, LibWhatever, AddonName1, AddonName2, YourAddonNameHere, AddonName3, AddonName4 etc.
-> So to say for each txt (manifest) file that is found within live/AddOns and up to 3 subfolders depth!
That's why you need to compare the addonName with the loadedAddonName parameter of that callback function of the event, else you would load your addons code too early (e.g. you would load your code as the LibAddonMenu-2.0 get's curently loaded and at that time some needed dependencies are missing or anoher lua/XML file of your addon was not properly loaded yet etc.)
or, like in your example, unregister your EVENT_ADD_ON_LOADED again too early before your addon was processed (addon.InitializeUI() was never executed).
If your addon was found, by comparing the loadedAddonName, you can safely unregister that event's callback so the code is not executed for AddonName3 and AddonName4 etc. anymore.
Keeping the event registered would only make sense if you want to list all loaded addons (like LibDebugLogger does) or if you want to check, by the addon name, if any other addon was loaded -> But there often exist easier ways like adding an ## OptionalDependsOn: LibAddonMenu-2.0 or ## DependsOn: OtherAddonNameHere so that these addons/libraries get loaded BEFORE your addon, in the load order of the txt files.
Or you can check for any global variable like if LibAddonMenu2 then --LibAddonMenu2 was loaded end
More details about load order, txt (manifest) files, dependencies etc. can be read here:
https://wiki.esoui.com/Addon_manifest_(.txt)_format
https://wiki.esoui.com/Libraries
Or join us at the chat:
https://app.gitter.im/#/room/#esoui_esoui:gitter.im