For Loop with Multiple Variables


Andre

Recommended Posts

I've been programming in C++ for 25 years and have never used that form of the for().  I'm not sure I ever knew it existed, though more likely, I just forgot about it having never needed it in the 10 years prior to first learning C++.  I personally think its one of those weird shorthands in C that can be achieved using a simpler setup that is easier to read.  As such, it was not incorporated into DAQFactory, just like most of the C/C++ shorthands.

So, since I have never used this loop format, and don't even remember it, I don't know exactly how it works.  The first and third part are pretty obvious, but the condition I'm less sure.  Does the loop stop only if both conditions are meant, or does it stop if either condition is met?  

Anyhow, you can replace this in several ways.  If you want to stick with a for() loop, you can manually initialize and increment one figure:

f = 0
for (i = 0, (i < 5) && (f < 5), i++)
   ...
   f+=5
endfor

(replace the && with || depending on the answer to my question in the second paragraph).  

Of course you can also do it with a while loop.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.