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?

Mukesh Ingham
  • 1,401
  • 8
  • 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
  • 857,932
  • 118
  • 1,152
  • 1,264
0

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

Forklift
  • 929
  • 11
  • 19