Can't we use normal iterations in a container?

We do use iterators to iterate over the elements of the containers. Can’t we use for loop or while loop to iterate over the containers?. If no, then why?. If yes, then why we are iterating using iterators not those for loops and how to use for loops to iterate over containers, if yes?.

hi @subham221

yes you will definetly use loops to iterate in any container

but you can’t use int i
for(int i=0;i<n;i++)
i is an integer variable but your container is not just an integer
for exp map is not an integer it contains pairs
so you have to use iterator for traversing in any container

An iterator is an object (like a pointer) that points to an element inside the container. We can use iterators to move through the contents of the container.

i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course