1
$\begingroup$

Can I use for loop for two variables as example show below at the same time?

for (int x = 0, y = 0; x < 10 && y < 10; x++, y++)

$\endgroup$
  • $\begingroup$ @Nasser I won't mind any method but still at the same time increment in two variables, I was not able to do it..... $\endgroup$ – Muhammad Ali Jul 5 at 12:50
  • $\begingroup$ @Nasser It worked Thanks!! $\endgroup$ – Muhammad Ali Jul 5 at 12:55
  • 1
    $\begingroup$ More idiomatic in Mathematica would be something like Table[expression,{x,0,10},{y,0,10}]. Depending on what you're doing, you might use something other than Table, or even avoid the need for x and y by using something like Map. But you'll have to show us what you're trying to accomplish for us to help with that. $\endgroup$ – John Doty Jul 5 at 12:56
2
$\begingroup$

The For loop works just fine in the Wolfram Language, so I won't try to dissuade you from using it. Though I don't use it myself I've seen a resurgence in its use with the new compiler.

For[
    x = 0;
    y = 0
    ,
    x < 10 && y < 10
    ,
    x++;
    y++;
    ,
    Print[x, " and ", y]
]

results in this print:

0 and 0

1 and 1

2 and 2

3 and 3

4 and 4

5 and 5

6 and 6

7 and 7

8 and 8

9 and 9
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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