How to run a loop only once while having constant update on a sensor?

Instead of:

     x= analogRead(2);
    while(x>300)
    {
      tone(8,500);
    }

you mean:

    while((x = analogRead(2)) > 300)
    {
      tone(8,500);
    }

or

    x = analogRead(2);
    while(x > 300)
    {
      tone(8,500);
       x = analogRead(2);
    }

or

    while(analogRead(2) > 300)
    {
      tone(8,500);
    }