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)]}]
j
always evaluates to 5
Any assistance would be appreciated.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityHow 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)]}]
j
always evaluates to 5
Any assistance would be appreciated.
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]]}}
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 '19 at 15:09