Skip to main content
edited tags
Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375
edited tags
Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375
Tweeted twitter.com/StackMma/status/1044602853724229632
added 62 characters in body
Source Link

The command Do[Print[i], {i, 1, 3}] does what you expect: creates 3 output lines of 1, 2 and 3, in that order.

If one merges these output cells, then evaluates the original Do command, the output is now 3, then 2, then 1. When one deletes the output cells, the regular behavior returns.

It isn't that the Do loop is running backwards. When one does "the same thing" with

temp=temp = {}
Do[AppendTo[temp, i];
Print[i], {i, 1, 3}];
temp

the order of the Print command is reversed, but the contents of temp are still {1, 2, 3}, not {3, 2, 1}.

Why does this happen? Does Print write to a queue that is sometimes dumped in reverse order?

I am running Mathematica 11.0.0 on Windows 10

The command Do[Print[i],{i,1,3}] does what you expect: creates 3 output lines of 1, 2 and 3, in that order.

If one merges these output cells, then evaluates the original Do command, the output is now 3, then 2, then 1. When one deletes the output cells, the regular behavior returns.

It isn't that the Do loop is running backwards. When one does "the same thing" with

temp={}
Do[AppendTo[temp,i];
Print[i],{i,1,3}];
temp

the order of the Print command is reversed, but the contents of temp are still {1,2,3}, not {3,2,1}.

Why does this happen? Does Print write to a queue that is sometimes dumped in reverse order?

The command Do[Print[i], {i, 1, 3}] does what you expect: creates 3 output lines of 1, 2 and 3, in that order.

If one merges these output cells, then evaluates the original Do command, the output is now 3, then 2, then 1. When one deletes the output cells, the regular behavior returns.

It isn't that the Do loop is running backwards. When one does "the same thing" with

temp = {}
Do[AppendTo[temp, i];
Print[i], {i, 1, 3}];
temp

the order of the Print command is reversed, but the contents of temp are still {1, 2, 3}, not {3, 2, 1}.

Why does this happen? Does Print write to a queue that is sometimes dumped in reverse order?

I am running Mathematica 11.0.0 on Windows 10

Source Link
GregH
  • 1.9k
  • 14
  • 26
Loading