How to ComponentData to an entity at for loop?

I have a ComponentSystem and I inject the entities I want to iterate. I want to add an ComponentData and do simple operation when iterating the entities inside for loop but it gives me “InvalidOperationException: The NativeArray has been deallocated, it is not allowed to access it” error. It seems like it’s not allowed to add component to an entity while iterating inside for loop. Is that anyway way to do it?

check PostUpdateCommands

Thanks. Problem solved.