Computer Programming Survey (Please Read).

  • Thread starter Thread starter A12
  • Start date Start date
Can you explain the difference please?
(not doubting you, i just dont actually know)

In a for loop you would generally know how many loops you are performing, you go into the loop knowing exactly what you are achieving. For example you want to iterate through 100 lines of data and remove any special characters like " ' and \. It's an iteration, you can see it as 100 individual iterations, executed through a loop statement. You know that loop 55 of the statement is applying to line 55 of your data.

In a while loop you may not know how many loops will occur, it might loop until something happens. For example you want to move a square on the screen until the top of it hits the screen upper boundary. You are not iterating, you are merely testing for a condition while doing something that changes that condition until it breaks the loop.

At least, that's my basic understanding of it. One could argue in the second example you are iterating through conditions and testing against them though.
 
Last edited:
Iteration has nothing to do with objects, just means repeating process. I suppose people relate it to objects because implementations of iteration pattern operated on objects.
 
Done!

It is most definitly a loop and not an iteration - In an iteration you have a value/object (an Iterator in java, for example) that you can refer to to get a point of reference to where you are in the loop, or use in the next iteration. Whereas, in a while loop there is no point of reference, unless you create a variable outside it and alter it within the loop.

I'm aware that may not be a text-book definition, but it's how I distinguish the two!
 
My understanding of this little debate: Making distinctions between iteration and loops, at a conceptual level, seems like splitting hairs. To iterate literally just means to do something repeatedly. You use loops to implement iteration. This is different to iterators (e.g. that in the C++ STL) which implement the iterator pattern, which allow you to iterate through all the items of some container. It's all kind of semantic anyway.
 
When I 'think about it in my mind' I see an iteration as a loop whose conditions are linked to the statements that are executed. Position reference for example.
 
I take back my "iteration is more related to collections of objects" post. That is incorrect. I just do all of my coding with objects and didn't give the post any thought. You can think of an iteration as a loop with a concrete termination point. You may have reached the end of whatever collection you were looping over (foreach) or your index value has reached the limit (for) whereas a loop has whatever termination point you specify (while). You may terminate because you've encountered a certain string value or whatever. It is kinda splitting hairs though. That's my take on it anyway.
 
I take back my "iteration is more related to collections of objects" post. That is incorrect. I just do all of my coding with objects and didn't give the post any thought. You can think of an iteration as a loop with a concrete termination point. You may have reached the end of whatever collection you were looping over (foreach) or your index value has reached the limit (for) whereas a loop has whatever termination point you specify (while). You may terminate because you've encountered a certain string value or whatever. It is kinda splitting hairs though. That's my take on it anyway.

Sounds about right to me.

Practical example in fake-code

'Usage of loop to dump lines from a file to array, no known specific termination point
While !EOF
arrayLines() = currentLine
Loop

'Iterate through array and capitalize entries, known termination point, loops occur against known number of entries in an array
For i = 0 to countsize(arrayLines)
uppercase(arrayLines(i))
Next i
 
Not wanting to throw petrol on the fire, but mathematically, iteration has absolutely no requirement to have a pre-defined count. In practice it is generally implemented as an open-ended process with some stop criteria (akin to a 'while' loop in c).

For example, a nonlinear iterative numerical method (as is required to solve any nonlinear PDE) involves a series of linearisations, followed by assesment of a "change-norm" - a quantification of how much the solution changes from one iteration to the next. The iterative procedure ceases only when the changenorm drops below a predefined threshold (the convergence criterion).

The nomenclature in programming may be different, but in mathematics an iterative procedure is almost always open-ended (i.e. 'while loop' rather than 'for loop').
 
The mathematical definition (And actual usage) is far different to the programmatic one. That's not to say you cannot perform a mathematical iteration through programming, because obviously you can, but there is a key distinction between 'iterations' in each case.
 
*
6. Has being taught programming in school led to a career in the field?

Didnt start til uni.

(Done btw)
 
Shouldn't you also be looking at people who were taught zero programming?

There should be an option for none then all you questions should lead on from "if yes move to question 2"

Another survey that seems flawed, maybe its just me but isn't this going to mess up your data?
 
Back
Top Bottom