I’ve come across a for loop structured in a way I’ve never seen before. I’m wondering if you can explain to me what it is doing? It is provided as one of the examples for verlet integration in Processing:
http://www.openprocessing.org/sketch/17191
Here is the code:
for(VerletParticle2D p : physics.particles) {
ellipse(p.x, p.y, 5, 5);
}
Is it simply adding an ‘p’ particle until it reaches the amount that has been setup before?
It’s the so-called “for each” loop. It simply iterates over all elements of the collection (or array)
physics.particles, assigning each element in turn top.For further information, see Oracle documentation.