Smooth for loop? (for generating games like terarria and minecraft)

I am doing a terarria like game and to make the generation happen I use 2 for loops.
One for x and one y generation.
However, every time it generates there is a clear lag.

In games like minecraft and terraria they have a loading bar that causes almost no lag…

How can I achieve that in unity?

You will have to do this on a seperate thread. That’s not a feature that’s Unity related though, it’s C# based. There’s plenty of resources you can dig also with examples related to Unity.
What basically happens is that Unity’s main thread stalls for the time it takes to generate your data. Doing this on a seperate thread will calculate this in parallel so Unity can continue. The threaded task does not have a finished percentage on its own though, You’d need to split your working tasks yourself, count the whole iteration loop and update some variable every now and then to know when you’re finished.
Be aware that you mustn’t use any Unity API except for basic data types, structs and custom classes (think that’s about that).