Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between an iteration and a loop?

I am doing Cs50 Harvard University online and I'm on week 3 but while watching the video I noticed that I iterations and loops seem the same, as they repeat things over and over. But there must be a difference or else they wouldn't have two names for the same thing. No matter how many times I re-watch the video I can't find a difference. Please help me understand.


1 Answers

"Loop" refers to language constructs that are used to repeatedly execute some code. (for loops, while loops, etc.)

"Loop" can also refer to code being executed repeatedly. (e.g. "It's stuck in a loop.")

Iterating is the process of doing something repeatedly. (e.g. "This loop iterates over the elements of the array.")

An iteration is a single pass of a loop. (e.g. "In the first iteration of that for loop, i will be 0.")

like image 141
ikegami Avatar answered Feb 19 '26 12:02

ikegami