Search Unity

Help With For Loops?

Discussion in 'Scripting' started by ObviousCyclone, Jan 7, 2014.

  1. ObviousCyclone

    ObviousCyclone

    Joined:
    Jul 13, 2013
    Posts:
    1
    Code (csharp):
    1.     for (changingIndex = survivorIndex, looped = 0; closestSurvivor == null   changingIndex < survivorTags.Length || looped < 4; changingIndex++, looped++)
    2.                     {
    3.                         closestSurvivor = GetNearestObject(survivorTags[changingIndex]);
    4.                     }
    It tells me an error of (,) .

    Please Help! Thanks in Advance.
     
  2. Robin-Hasenbach

    Robin-Hasenbach

    Joined:
    Jan 7, 2014
    Posts:
    5
    I wouldn´t actually check the 'looped' variable in the head of the for-Statement.
    Actually I would advice you to store the looped in an int above the for-Statement and do the check for the loops inside of the for-Statement and count them up there.

    Here´s the Code:

    Code (csharp):
    1.  
    2. int looped = 0;
    3.  
    4. for (changingIndex = survivorIndex; closestSurvivor == null  changingIndex < survivorTags.Length; changingIndex++)
    5. {
    6.     if(looped < 4)
    7.     {
    8.         break;
    9.     }
    10.     else
    11.     {
    12.         closestSurvivor = GetNearestObject(survivorTags[changingIndex]);
    13.         looped++;
    14.     }
    15. }
    16.