Andre Posted September 25, 2016 Share Posted September 25, 2016 Good Day I want to add two variables to one for loop. Below is how it is done in C++. How can I do this in Daqfactory? for (i = 0,f = 0.0; i < 5,f < 5; i++, f+=5) Thank you. Link to comment Share on other sites More sharing options...
AzeoTech Posted September 28, 2016 Share Posted September 28, 2016 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 More sharing options...
Andre Posted September 28, 2016 Author Share Posted September 28, 2016 Thanks. I did exactly what I wanted to do using a While() loop with if statements. Kind Regards Andre Link to comment Share on other sites More sharing options...
AzeoTech Posted September 28, 2016 Share Posted September 28, 2016 You shouldn't need an if, just a while. Sorry for treatise before, but I'm curious what the benefit of using a for loop like you described is. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.