Jump to content
Search Community

Just another hitTest

mikel test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

16 hours ago, mikel said:

In the last 12 months, I learned some JS / JQUERY. But there is still a long way to go ...

 

Nice work! Now where did you learn to write loops like this? ?

 

var i = lines.length;
while (--i > -1) {
  ...
}

 

 

Jack's the only person I know of that writes code like that. I know it used to be faster to write backwards running loops like that. Not sure if that's still the fastest way, or if it even matters. When GSAP's code gets minified, it converts all those while-loops into for-loops, and switches stuff around.

 

But seeing that reminded me of a question I was asked during an interview. I couldn't answer it at the time, but let's see if anybody else can.

 

What will this output?

 

var i = 3;

while(i --> 0) {
  console.log(i);
}

 

 

I was totally confused by the arrow ( --> ), which I've never seen before. 

 

  • Like 1
Link to comment
Share on other sites

Hi @OSUblake,

 

Instead of MDN lessons  I try to find examples here in the forum. I'm pretty sure I found this syntax in an example from GREENSOCK.

 

By the way: "The usage of --> has historical relevance. Decrementing was (and still is in some cases), faster than incrementing on the x86 architecture. Using --> suggests that x is going to 0, and appeals to those with mathematical backgrounds." 

 

Best regards

Mikel

 

 

  • Like 2
Link to comment
Share on other sites

15 hours ago, mikel said:

Using --> suggests that x is going to 0, and appeals to those with mathematical backgrounds." 

 

DING DING! We have a winner. ?

 

 

For those that don't get it, it's not an arrow, but a decrement and a greater-than symbol sitting next to each other without a space. So it's really this.

 

while (x-- > 0) {

}

 

 

Some programmers use the arrow to show what the value is going to, which does make sense once you understand its meaning. So x goes to 5.

 

while (x --> 5) {

}

 

 

In languages like C++, you can do some even weirder things, like chaining the increment/decrement operator together. This will decrement by 2.

 

while (0 <---- x) {
  
}

 

 

Decrement by 10

 

while (0 <-------------------- x) {
  
}

 

 

Decrement by 10 with Lazers. Pew Pew!!!

 

while (0 > - - - - - -- -- -- -- -- ---------- x) {
  
}

 

 

And the most important one, x slides to 0. Wheeee!!!

 

while (x --\
            \
             \
              \
               > 0);

 

 

Demo

http://coliru.stacked-crooked.com/a/4109c1dbf6b4f294

 

 

  • Like 1
  • Haha 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...