What is the need of iterators?

If we can iterate over the string using simple loop. Then why we need iterators? Is there any benefit of using iterators?
Because in both cases we are using one loop.

@itismohiton

hello Mohit,
a) performance wise i think there is not much difference
b)Using iterators makes the for-loop slightly simpler, you can avoid typo-type mistakes by using the wrong index or wrong symbol
c) The main advantage of using iterators is generality. That is, you can write only one function and use it for different containers:

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.