Hello Deena,
It is a bad practice to commit inside the loop, because this will trigger a commit to the database on every iteration. However if you commit a list, everything is commit in a single batch.
To be able to commit a list, you first have to have a list. There are probably 2 main scenarios:
In the first scenario, you would make changes inside the loop and commit the list of objects ouside of the loop.
In the second scenario, you would have to create a new list prior to looping. Then inside the loop you create the object followed by adding it to the newly created list. After the loop you can commit the list at once instead of committing every single object inside the loop.
Does this answer your question?