# Building a table from two lists taking every element from the 1st list and every 5th from the 2nd

How do you get a conditional to work in the bounds of a Table:

Table[{A[[i]], "->", B[[j]]}, {i, 2}, {j, If[j = 1, 5, (5*i)]}]


jalways evaluates to 5

Any assistance would be appreciated.

• Try A=Table[r,{r,5}];B=Table[q,{q,10}];Table[{A[[i]], "->", B[[ If[j == 1, 5, (5*i)]]]}, {i, 2}, {j,2}] and see if that is what you want. If this doesn't solve your problem then please edit the question to help me understand what you are trying to do. Also look up = and == in the help system and try to see the difference in those. – Bill Aug 25 '19 at 15:09
• That will work Thank You – Michel Mesedahl Aug 25 '19 at 15:37

First, j is always 5 because you write

If[j = 1, 5, (5*i)]


when you should write

If[j == 1, 5, (5*i)]


That is, you are assigning 5 to j, not testing to see if it is equal to 1. But note, since 5 is the same as 5*1, you just want j to be 5*i for all i. Therefore, you don't need j at all but can just write

Quiet @ Table[{A[[i]], "->", B[[5 i]]}, {i, 2}]


{{A[[1]], "->", B[[5]]}, {A[[2]], "->", B[[10]]}}

• I have 2 files A and B. I want to combine them . For every entry in A I want to associate the first 5 entries of B A[1]->B[1] . . A[1]->B[5] Then A[2]->B[6] . . A[2]->B[10] So for every line in A, I will have 5 lines from B File will look like this A[1]->B[1] A[1]->B[2] A[1]->B[3] A[1]->B[4] A[1]->B[5] A[2]->B[6] A[2]->B[7] ...... The issue with the Table Form is that I need the change the imin. Table[expr,{i,imin,imax}] I am not sure a Table form can do this. – Michel Mesedahl Aug 25 '19 at 16:20
• Please disregard. Whole issue has been resolved. Thank You for your time Michel – Michel Mesedahl Aug 25 '19 at 17:07