I wanted to learn about while and do while loops. No problem with a simple "Blink" while loop, but the do while doesn't stop after the index goes over the condition. Seems simple.. why won't it stop?
AWOL:
Because it is in "loop()" which gets called over and over again.
Actually, the "problem" is in the nature of the do/while loop (which is why I NEVER use that construct).
The body of the do/while statement is executed, and THEN the condition is checked. What is happening is that on the first call to loop(), the do/while body is executed 4 times. Then, it ends, and loop() is called again. The body of the statement is executed, and the while conditions then says "Oops, that's enough of that", and the do/while ends, and loop() is called again.
That may be too dogmatic. The key to keep in mind is that a do-while always makes at least one pass through the loop regardless of the test condition(s) at the bottom of the loop. A regular while loop may have the test expression such that the statements in the while statement block are never executed.
I've been writing C/C++ code for a living for 25+ years. I've never used a do/while loop. I can't imagine a situation where I'd want the body of the statement executed once unconditionally, and then 0 or more times conditionally. IF that situation ever arose, comments, some code, and a while loop would make orders of magnitude more sense. The code would be in a function, too.