# Conditional Table

I have following :

SeedRandom[2]
Table[Table[RandomInteger[100, {100, 10}][[r, s]] == x[r + s], {r, 1, 10}], {s,1,10}]


How can I set condition inside Tables?Such as if r>s set 40 times of x value?Or something like this ?I want to have many of those conditions inside two tables?

Any suggestion for using other commands?

• not really answering your question, but avoiding Table(you could specify r and s in the same table anyway), you could generate the RandomInteger directly and apply the condition on the pairs, e.g. like: If[#1 > #2, "a", "b"] & @@@ RandomInteger[100, {100, 2}] – Pinguin Dirk Nov 21 '13 at 20:07
• Where is x defined in your code?? – Nasser Nov 21 '13 at 20:08
• @PinguinDirk thanks but instead of Random I have real data .I just put that random to show some number. – Alex Nov 21 '13 at 20:09
• @Nasser it variable.I need it that way.for example I need x[12] multiply to two cause in 9+3, we have 9>3. – Alex Nov 21 '13 at 20:10
• Ok, I see, I thought it was a list at first. – Nasser Nov 21 '13 at 20:18

Table works much like Do -- you can have any number of statements inside. For instance:

Table[r = 100; statement1; statement2; RandomReal[{-1, 1}], {i, 1, 10}]


Here the r = 100 doesn't do anything, and the statements can be anything -- just separate them with a semicolon. The final term (in this case a RandomReal) occurs without semicolon and is the thing that is returned in the Table.

• Many thanks!!!! – Alex Nov 22 '13 at 6:19

I am not all sure I grasp your question, but perhaps you're looking for MapIndexed.

SeedRandom[2]; data = RandomInteger[100, {5, 3}]

{{92, 57, 22}, {84, 63, 1}, {81, 96, 19}, {38, 67, 68}}

MapIndexed[If[#2[[1]] > #2[[2]], 40 #1, #1] &, data, {2}]

{{92, 57, 22}, {3360, 63, 1}, {3240, 3840, 19}, {1520, 2680, 2720}}