01-16-2018 03:36 AM
Hey there,I'm an idiot who spent the past 2 hours trying to do something really simple but failed to do it.
Basically i have a number(lets call it X) this number needs to be higher than Y(another constant), and if it its not , i want to keep multiplying X by 2 until X is bigger than Y, what i'm failing to do is the loop for some reason, i keep getting " wire is a member of a cycle".
Thank you all
Solved! Go to Solution.
01-16-2018 03:43 AM - edited 01-16-2018 03:45 AM
Hi Hamza,
some pseudocode:
while x < y x := 2*x wend
All you need is a simple while loop with a shift register, a comparison and the "*2" part…
Maybe you should post your VI so we can tell what you made wrong?
(There also is a loopless solution possible using the binary logarithm…)
01-16-2018 04:12 AM - edited 01-16-2018 04:29 AM
Thanks a lot Im off to a new problem now, the while loop keeps looping without giving value to out of the loop.
the only part you need to pay attention to is the top right part, the inside of the True part of the case structure.
Thanks!
Edit:Update the vi a little, simple problem
01-16-2018 04:34 AM - edited 01-16-2018 04:35 AM
Hi Hamza,
the while loop keeps looping without giving value to out of the loop.
THINK DATAFLOW!
The loop keeps spinning because the loop condition is calculated before the loop and will NEVER changes inside the loop!
You need to do the comparison INSIDE the loop!
the only part you need to pay attention to is the top right part,
Well, no… 😄
- use shift registers instead of feedback nodes, they are easier to understand for LabVIEW beginners (IMHO)…
- use the Select node instead of a case structure when you just want to switch between two values…
- NEVER hide or delete the label of terminals in the block diagram!
- use AutoCleanup from time to time!
- put a wait in your loop to prevent it from spinning as fast as possible! (That's not needed for UI handling…)
01-16-2018 05:59 AM - edited 01-16-2018 06:03 AM
the only part you need to pay attention to is the top right part,
Well, no… 😄
I meant the whole vi not the case.
As you can tell, i'm still learning labview ,So thank you so much for the tips, super helpful, i didnt even know there was an auto cleanup!.
Great job! thanks!
- use the Select node instead of a case structure when you just want to switch between two values…
Could you please explain whats the advantages besides being cleaner? i just find case structures a lot easier to read and understand,and its easier to modify
01-16-2018 06:40 AM
Hi Hamza,
Could you please explain whats the advantages besides being cleaner?
Isn't it enough justification to provide cleaner code? 😄
In your case you just select one of two wires, no other operations involved: in this case I prefer the Select node as I immediatly see what is happening in the code for both TRUE/FALSE cases.
When there are lots of other code for each of both cases I put them inside a case structure to have the CPU only do the needed stuff…
01-16-2018 06:41 AM
@HamzaR wrote:
Could you please explain whats the advantages besides being cleaner? i just find case structures a lot easier to read and understand,and its easier to modify
The Select node does not hide code like the Case Structure. So it is usually better to just use the Select node for simple choices on a single value (easier to see the full flow of data).