What do you want to actually do with the original block of code? Just search for prime numbers?
And btw, in your last example, a new x is created. To you, the programmer, it appears that you have two x's, but to the compiler, they are separate variables, with separate addresses. Local variables only last from their declaration until the ending brace of whatever block they are in.