LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Quick Q from a begginer about "For loop"

Hi guys

 

I am trying to learn and practice For loop, I was doing an example on that topic "Create a VI to add „5‟ to a number if it is greater than ‟10‟, else add ‟10‟."

 

I done everything except one thing I couldnt figure out the "Add Array Elements Function", something in the picture comes before it, I dont it with out it and it works, but does it matter if I dont use it? and where can I find that Pallete? and whats its job?

 

 

I uploaded a picture of the example and circuled the uknown Pallete

 

 

 

Mash

 

 

0 Kudos
Message 1 of 8
(3,120 Views)

Hi meow,

 

To answer your question: that's BuildArray, reduced to just one input.

 

I don't see any relation between your picture and your topic. How can you say "done everything"?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(3,115 Views)

It is "built array" from the array palette, resized for height=1 and configured to "concatenate inputs" (right-click...).

In this case it does not do anything useful and can be left out without any change in program functionality.

 

Also note that your "input" control and "output" indicator have the wrong representation. (they should be blue, not orange). There is also a "+1" primitive.


meow2014 wrote:

I am trying to learn and practice For loop, I was doing an example on that topic "Create a VI to add „5‟ to a number if it is greater than ‟10‟, else add ‟10‟." 


The code in the picture has absolutely nothing to do with this problem.

 

Also, next time try to write a more useful post title. Your post is not a question about a "for loop". Right?

0 Kudos
Message 3 of 8
(3,112 Views)

sorry guys I copied and pasted the wrong question

 

the question was:

Create a VI to output the sum of numbers from 1 to the number input.

 

 

 

I done it and when I enter the input 3 I get 0

 

what could I have done wrong?

 

I have uploaded the VI file that i done

 

 

0 Kudos
Message 4 of 8
(3,098 Views)

You can enter any positive value and it will return zero, as the loop only executes once.

 

If you run the VI with execution highlighting switched on (the lightbulb on the block diagram), you might be able to see why the loop will only execute once. Hint: what are you comparing in the greater than or equal node?

 

Also, you'll want to read up about output tunnels in loops. The output tunnel from that while loop is set to last value...which doesn't help you calculate the sum of all the numbers.

---
CLA
0 Kudos
Message 5 of 8
(3,091 Views)

@meow2014 wrote:

what could I have done wrong?


First of all, you need a FOR loop, not a while loop (because you know the number of iterations before the loop starts!).

 

Look at the code picture you attached earlier for some clues.

 

Your terminal are still in the wrong representation. You are dealing with integers here!

0 Kudos
Message 6 of 8
(3,085 Views)

1. Use a FOR loop.

2. Look into Shift Registers.  They can make your life a lot easier here (and more efficient).

 

And just to make sure somebody covers it, here's a bunch of links to free LabVIEW training material.

3 Hour Introduction
6 Hour Introduction
LabVEW Basics
Self Paced training for students
Self Paced training beginner to advanced, SSP Required
LabVIEW Wiki on Training
Learning NI
Getting Started with NI Products


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 8
(3,052 Views)

@meow2014 wrote:

sorry guys I copied and pasted the wrong question

 

the question was:

Create a VI to output the sum of numbers from 1 to the number input.

 

 

 

I done it and when I enter the input 3 I get 0

 

what could I have done wrong?

 

I have uploaded the VI file that i done

 

 


What's wrong: Basically everything, but only slightly.

Switch the Greater than-connectors.

Change the loop output to Indexing

Remove the Build array.

Then it'll work. 🙂

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 8
(3,022 Views)