From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

repeat string in a for loop

Solved!
Go to solution

Hi there,

 

I am new to Labview, and have been stuck on a problem for a while, would anybody kindly help me out please?

 

Here is the question, I need to repeat a string in a for loop. let's say the iteration number N is 20, I would like the output from the for loop is

1, 2, 3 , ..., 9 , 10, 1, 2, 3 , ..., 9 , 10.

 

Thanks very much for your help!

 

Regards,

Raul

 

0 Kudos
Message 1 of 5
(3,417 Views)

Hi Raul,

 

according to the given example I would program this pseudocode:

FOR i := 0 to 19
  string[i] := num2string( modulo( i; 10) + 1)
NEXT

Remember: creating an array from a loop is easily done by utilizing AutoIndexing…

 

Using LabVIEW you can also create this code:

FOR i:= 0 to 19
  a[i] := i
NEXT
a[] := modulo( a[]; 10) +1
stringarray[] := num2string( a[] )
string := Array2SpreadsheetString( a[] )
Best regards,
GerdW


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

Thanks,GerdW!

 

I was thinking if there is a easy way to do that, like using the I in the for loop, it automatically gives number from 1 to 20, I just need to repeat the first half out it.

 

Regards,

Raul

0 Kudos
Message 3 of 5
(3,398 Views)
Solution
Accepted by topic author Raul6128

Hi Raul,

 

it automatically gives number from 1 to 20, I just need to repeat the first half out it.

Why not the other way around: create just half amount of those numbers and use BuildArray (or ConcatString) to use those values twice?

 

"Programming" most often has to do with being able to abstract a problem to develop an algorithm… 😄

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 5
(3,392 Views)

Thanks! The problem has been solved by concatenating the output from the for loop.

 

Cheers,

Raul

0 Kudos
Message 5 of 5
(3,345 Views)