Home do-while loop starts at zero
Reply: 0

do-while loop starts at zero

user9936
1#
user9936 Published in September 19, 2018, 9:09 am

What I'm aiming at is systematically increase the value of e1 from -1 to 0 in steps of 0.001. And with each value of e1, compute variable uNew with increasing values of the variable r by dr = 0.01 until r = 25;

But the energy keeps starting at zero instead of -1, And I can't figure out how to implement it, also, should I use two For loops?

 for(int i = 0; i < 1000 ; i++) {
     do {                                      
         e1 = e1 + 0.001;                  
     }while(e1 < 0 );                                                                        


      r = i*dr;
      uNew = 2*u1-u0+dr*dr*(2/r - 2*e1)*u0;            

      dr += 0.01;       
      u0 = u1;
      u1 = uNew;            
  }                                         
share|improve this question
  • You already have two loops - what ya talking 'bout? – Scary Wombat Apr 17 at 6:28
  • 1
    It would help if you could actually write out the equation using math notation. Then, someone can help you to translate it into Java code. – Tim Biegeleisen Apr 17 at 6:28
  • Tim is correct like this we are not able to understand your requirement – Lokesh Apr 17 at 6:29
  • 1
    why even do the do-while loop, if you could just as well initialize e1 to 0, because it will only be used as 0? – XtremeBaumer Apr 17 at 6:29
  • The first thing you do at each iteration of the outer for loop is to increment e1 in an inner loop until it's >= 0. Just don't. Increment it once. – JB Nizet Apr 17 at 6:29

1 Answer 1

active oldest votes
up vote 0 down vote
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.432148 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO