Search Unity

For loop confusion...

Discussion in 'Scripting' started by Mr. Animator, Feb 8, 2006.

  1. Mr. Animator

    Mr. Animator

    Joined:
    Oct 2, 2005
    Posts:
    193
    Okay, I must be going crazy... I can't find a single example of a for loop that doesn't increment by ones. I want one that increments on two's... I've googled it to death and keep finding this kind of example...

    Code (csharp):
    1. for (i = 0 ; i <=10 ; i=i+2)
    But unity gives me syntax errors if I use anything other than a simple i++ for the increment. Any ideas?
     
  2. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Can you use:

    Code (csharp):
    1.  
    2. //for Javascript
    3. var i = 0;
    4. While (i<=10)
    5. {
    6.     //do stuff
    7.     i += 2;
    8. }
    9.  
    would do the same thing.

    -Jeremy
     
  3. Mr. Animator

    Mr. Animator

    Joined:
    Oct 2, 2005
    Posts:
    193
    Yeah I could, I just wanted to get to the bottom of why that doesn't work. :)
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Appears to be a bug in the javascript compiler. Will be fixed with the next release.
     
  5. aigam

    aigam

    Joined:
    Dec 31, 2005
    Posts:
    170
    This is bad, the correct one is:
     
  6. aaronsullivan

    aaronsullivan

    Joined:
    Nov 10, 2005
    Posts:
    986
    Wha! I know you are trying to help, but that's simply not true in any language I know of. There is no semicolon after the third parameter. The first example is written correctly. It's already confirmed that it's a compiler error. Please don't post something unless you are 100%. If not, just look it up first. For instance, Google: for loop javascript example.

    Sorry for reacting strongly but I just don't like seeing false info posted in the thread.
     
  7. aigam

    aigam

    Joined:
    Dec 31, 2005
    Posts:
    170
    Sorry, you are true. It's my fault, please delete the posts.