What is the difference between for and foreach?

a for loop is a construct that says “perform this operation n. times“.

a foreach loop is a construct that says “perform this operation against each value/object in this IEnumerable”

Leave a Comment