Am I using while loops incorrectly?

I’ve written a code that generates random position of x and y when it’s not in a list. This is the code:

void startChar(){
		Vector3 pos;
		List<Vector3> posArr = new List<Vector3> ();
		pos.x = 0;
		pos.y = 0;
		pos.z = 0;
		for (int i = 0; i < population; i++) {
			pos.x = Random.Range(0, Screen.width - 63) / 100;
			pos.y = Random.Range(0, Screen.height - 63) / 100;
			posArr.Add(pos);
			while (posArr.Contains(pos) == true){
				Debug.Log ("StartChar: While");
				pos.x = Random.Range(0, Screen.width - 63) / 100;
				pos.y = Random.Range(0, Screen.height - 63) / 100;
			}
		}
	}

But sometimes it still generates the same position, I don’t know what’s wrong, or maybe I used the while loop incorrectly.

Your approach is workable, but your logic is flawed. Try this (untested):

   for (int i = 0; i < population; i++) {
        do {
            pos.x = Random.Range(0, Screen.width - 63) / 100;
            pos.y = Random.Range(0, Screen.height - 63) / 100;
        } while (posArr.Contains(pos));
        posArr.Add(pos);
    }

Note I shy away from infinite loops like this one for solving this problem. The issue is that if you ever end up with condition where there is no solution, your app will hang. Instead I might do something like:

   for (int i = 0; i < population; i++) {
       for (int j = 0; j < 1000; j++) {
            pos.x = Random.Range(0, Screen.width - 63) / 100;
            pos.y = Random.Range(0, Screen.height - 63) / 100;
            if (!posArr.Contains(pos) break;
        } 
        posArr.Add(pos);
    }

This way it will try for 1000 times to find a workable position, and if it cannot find one, it just uses the last position. You get duplicates if no workable position is found, but the app will not hang.