472,953 Members | 1,748 Online

# recursiveness using bool...

I hav a code like this

Expand|Select|Wrap|Line Numbers
1. i=0
2. while i<n:
3.     xold.data[0][i]=float(self.enINITGUESS.get());   #INITGUESS is an initial value
4.     xnew.data[0][i]=xold.data[0][i];
5.     i=i+1
6. i=0
7. flag = 1
8. if True:
9.     flag=0
10.     for i in range (n):                  # all this is for improving my xnew
11.         j=0
12.         temp=0
13.         while j<i:
14.             temp=temp+a.data[i][j]*xnew.data[0][j]    #a,b,xnew,xold are classes #defined earlier
15.             j=j+1
16.         j=i+1
17.         while j<n:
18.             temp=temp+a.data[i][j]*xold.data[0][j]
19.             j=j+1
20.         xnew.data[0][i]=(b.data[0][i]-temp)/a.data[i][i]
21.         s1=xold.data[0][i]
22.         s2=xnew.data[0][i]                          #evaluating the results differences
23.         e.data[0][i]= s1-s2
24.         if e.data[0][i]<float(0):
25.             e.data[0][i]=0-e.data[0][i]
26.         i=0
27.         for i in range (n):
28.             xold.data[0][i]=xnew.data[0][i]
29.         if e.data[0][i]>float(self.enPREC.get()):  #if more than a certain value iterate #again using the newly defined xold
30.             flag=1

evidently this code does not seem to reiterate... it jus perform the operation once only.... even if it finds tht the difference exceeds the given value specified by PREC it doesnt iterate again... it jus throws out the result of the calculation given by its first attempt on it... anybody care 2 help?
Jul 13 '07 #1
1 981
elbin
27
evidently this code does not seem to reiterate... it jus perform the operation once only.... even if it finds tht the difference exceeds the given value specified by PREC it doesnt iterate again... it jus throws out the result of the calculation given by its first attempt on it... anybody care 2 help?
This code has no while statement dealing with flag, so I don't see how it could possibly iterate. Just replace the

Expand|Select|Wrap|Line Numbers
1. if TRUE:
with

Expand|Select|Wrap|Line Numbers
1. while flag:
and you'll have it.
Jul 13 '07 #2