I want to use a for loop to define a range and I would like to use a while loop to check a condition for every value inside this for loop and give me the results for different values of c, but unfortunately, my algorithm doesn't work and I don't know what my mistake is.
j=0
jl=[]
c=np.linspace(0,20,num=20)
for a in range(0,len(c)):
while j<5:
j=c[a]+2
jl.append(j)
The result I am looking for is it puts different values of c inside the while loop and calculate j and check if it is bigger than 5 or not. if yes, it appends it to jl. Totally, I want to define a range with for loop with index and also check each value of this range inside while loop and get the results for j. so expected results are j with values smaller than 5 (c[a]+2<5) and store the values of j in jl
j=0and your while condition isj>5so it never runs.jl.append(j)outside/after the for loop - is that intended? - it will only run once after the for loop is done.c[a]or useafor anything other than indexingc. Just iterate overcdirectly:for item in c: while j < 5: j=item + 2; ....