0

I saw some code online and it had this in it:

document.writeln("<p>");
for (var line = 10; line --> 0;) { // --> operator here
  for (var i = 10; i --> 0;) {     // --> operator here
    var s = (Math.floor((Math.random()*2)%2)) ? "╱" : "╲";
    document.write(s);
  }
  document.writeln("<br>");
}
document.writeln("</p>");
p { 
  line-height: 18px; 
  font-size: 18px; 
}

What exactly is this --> operator and what does it do?

EDD
  • 2,070
  • 1
  • 10
  • 23

2 Answers2

2

There isn't a --> operator.

That is just a Postfix Decrement Operator immediately followed by a Greater Than Operator.

It would more usually be written as:

for (var i = 10; i-- > 0;) { 
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

It is a decrement (--) followed by a comparison (>). These would normally be written with a space to make it easier to read.

Forklift
  • 949
  • 8
  • 20