- Home /
infinite loop
why is this an infinite loop? cant figure it out. each time it finds the file and it exists it should be adding 1 to userID. so each time the file name should change.
in the this directory im checking to see if a file exists. and if it does loop again, if not exit the loop.
so it shouldn't be an infinite loop but obviously ive done this wrong. please help :)
string tempfile = usersDir + userID + ".dat";
while(File.Exists(tempfile))
{
{
userID =+ 1;
tempfile = usersDir + userID + ".dat";
Debug.Log(userID);
}
}
Answer by Rob-Fireproof · May 16, 2014 at 04:09 PM
There's a tiny mistake on this line:
userID =+ 1;
That's basically assigning 1 to that variable every frame (change the formatting, and it looks like userID = +1, which is clearly wrong). It should be either
userID += 1
or
userID++;
Both of which will add one to the number.
Answer by SpaceSocks · May 16, 2014 at 04:15 PM
thank you Rob. :) silly me. I was looking at the loop didnt even think about that.
Your answer