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 :slight_smile:

string tempfile = usersDir + userID + ".dat";
			
		while(File.Exists(tempfile))
		{	
			{
				userID =+ 1;
				tempfile = usersDir + userID + ".dat";
				Debug.Log(userID);
			}
			
		
		}

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.

thank you Rob. :slight_smile: silly me. I was looking at the loop didnt even think about that.