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.

  • 1
    $\begingroup$ 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. $\endgroup$
    – Bill
    Aug 25, 2019 at 15:09
  • $\begingroup$ That will work Thank You $\endgroup$ Aug 25, 2019 at 15:37

1 Answer 1


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]]}}

  • $\begingroup$ 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. $\endgroup$ Aug 25, 2019 at 16:20
  • $\begingroup$ Please disregard. Whole issue has been resolved. Thank You for your time Michel $\endgroup$ Aug 25, 2019 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.