Reassign scalar value within for loop

Hi,
I need to update a scalar value used within the variational problem for each iteration (since it is a dynamic simulation).

Is there any way to do that employing the assign function (or other similar) in the For loop?

I need to avoid compiling the weak formulation within the For loop, for some reason, it does not converge inside the loop but outside of it.

Regards,
Santiago

Consider the following:

from dolfin import *
import time

mesh = UnitSquareMesh(10,10)
V = FunctionSpace(mesh, "CG", 1)
u, v = TrialFunction(V), TestFunction(V)
alpha = Constant(1)
a = alpha*inner(u, v)*dx
for i in range(4):
    alpha.assign(i)
    start = time.time()
    A = assemble(a)
    end = time.time()
    print(end-start,  A.norm("frobenius"))

This produces

Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
3.021070957183838 0.0
0.0009584426879882812 0.05157249482255294
0.0006306171417236328 0.10314498964510588
0.0006115436553955078 0.15471748446765718

As you can see, the form is only compiled once.

Dear Jorgen,
Thank you for the MWE! I will check it out!

Cheers, Santiago