Problems concatenating two lists using @for

list1:=Apple

Orange

carrot

List2:=

fruit

fruit

vegetable

@For(

n := 1; n <= @Elements(list1); n := n + 1;

tmp1:=@If(n=1 ;

list1[n]+" "+list2[n]

;

tmp1:list1[n]+" "+list2[n]

)

);

tmp1

Instead of getting

Apple Fruit

Orange Fruit

Carrot Vegetable

I see

Apple FruitFruitVegetable

Orange FruitVegetable

Carrot Vegetable

It’s like my second list it doesn want to use th[n] parameter!

Is it even possible to concatenate two text lists?

Thanks

ST

Subject: Problems concatenating two lists using @for.

Its ok thanks i figured it out, @for does a permutation concat…

ST

Subject: RE: Problems concatenating two lists using @for.

Its ok thanks i figured it out, @for does a permutation concat…

You took the wrong lesson from this. @For doesn’t do any concatenation. @For repeats the enclosed statements until its condition is met. You did the concatenation with this expression:

tmp1:list1[n]+" "+list2[n]

What you’re missing is that, first, : is a higher precedence operator than +, and second, when you concatenate a list with a scalar, it adds the scalar to each element of the list. You would have to write the expression this way:

tmp1:(list1[n]+" "+list2[n])

Except, of course, that as someone else pointed out, all you have to do is + the lists together.

Subject: But why not just add them?

list1:=Apple

Orange

carrot

List2:=

fruit

fruit

vegetable

Why not just use list concatenation?

(list1+" ")+list2

Subject: Problems concatenating two lists using @for.

To obtain the response you want, only this formula is needed:

lis1 + " "+ list2

Subject: RE: Problems concatenating two lists using @for.

Thanks. I realized that after I searched the help NSF for concatenation…

does anyone know why @for using [n] does NOT work, rather it concantenates two lists in a permutation form (which is logically, not what I expected)?

ST

Subject: RE: Problems concatenating two lists using @for.

Please read my earlier response in this thread.