Is it possible to for loop without using foreach and decision statements?is there any way to write that one using assign?


#1

is it possible to for loop without using foreach and decision statements?is there any way to write that one using assign?


#2

Not with Assign, as the loop itself doesn’t produce or store a value, thus can’t be used as either side of it.

Closest to a For loop is a While loop with a counter as the condition.
for (i = 0; i < something.Length; i++) { .... }
becomes:
i = 0; while (i < something.Length) { // some logic i++; }


#3

i kno this one.but actually i need usinng assign activity


#4

I was doing some research this morning with List.ForEach but unsuccessful with Invoke Method as well.

For eg : dt.AsEnumerable().ToList.ForEach(Function(x) list.Add(x)) ( adding dt rows to list)

This is a bad example, as the list it self is created(ToList), but was trying to explore more options.


#5

Right, you can use a For in a few ways within an Assign activity like what vvaidya is posting above.

I’m not an expert though. You can do something like this:
(From line In text.Split(vblf(0)) where line.StartsWith(“ABC”))

My example, takes a list of text and stores only certain lines to an array that meet a criteria.


#6

@harisankarreddy
I fail to see what you want to assign a loop to. Can you elaborate?

@vvaidya
Function needs to return something, yours doesn’t. It would need to be a .ForEach(Sub(x) list.Add(x)), but unffortunately Statement lambda's cannot be converted to expression trees., so I don’t know how to pass an Action<T> as a parameter to InvokeMethod.
Last time I just created an activity that would do what I wanted instead.

@ClaytonM
That’s not a For loop, it’s a LINQ expression in query syntax :slight_smile: Still, it returns a value so can be used in assign perfectly fine.


#7

lol, I know but for Assign you need to return a value so figured that’s kind of what he’s looking for. :stuck_out_tongue:


#8

I tried Action parameter as well, still gives me same message. Will rest the case partially now and re-try when I need