471,310 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,310 software developers and data experts.

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 934
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

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Saeed Amrollahi | last post: by
13 posts views Thread by kamaraj80 | last post: by
reply views Thread by Mona | last post: by
40 posts views Thread by Mark P | last post: by
6 posts views Thread by =?Utf-8?B?U2FtZWVrc2hh?= | last post: by
4 posts views Thread by Michael Bray | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.