• Resolved mewaqqas

    (@mewaqqas)


    Hi
    i am trying to create a form in which user will provide few inputs. based on which, form has to calculate required variable iteratively. so what i am trying:

      creating a loop (do-while loop) to solve for required variable iteratively.
      it solve the equation after user click at the “calculate” button.

    i have written the equation and its working as intended on local simple html page. but when i include it plugin calculate field and click at the calculate button. my browser become unresponsive.
    please guide me how can i achieve the goals.
    here is the code of loop including equation. before this loop i simply declaring the variable.

     do {
                Pcr=(Sigma*A)/(1+ec_over_r/COS(theeta*SQRT(old_force)));
              allowed_error= ABS(Pcr-old_force);
              old_force=Pcr;
              }
              while(allowed_error > 0.0001);
    return old_force;
    

    Pcr is the variable i need to find. while old_force=1 in first iteration.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @mewaqqas

    Please, send me the link to the form and the values you are entering for testing.

    First, the use of return instruction requires you be into the context of a function, like:

    (function(){
    /** YOUR EQUATION'S CODE HERE **/
    })()

    Furthermore, based on the values of the variables, the condition allowed_error > 0.0001 may never be true, and your code would be running in an endless loop blocking the browser.

    Best regards.

    Thread Starter mewaqqas

    (@mewaqqas)

    Thank You for your quick response.
    my problem got resolved. all i did is paste the equations again into the equation designated area while keeping the structure of code as you have suggested.
    allowed_error > 0.0001 was not the problem in my case as this condition become false in less than 10 iterations and terminate the loop. calculator is giving result as expected based on input.
    now My calculator is live on my website.

    Plugin Author codepeople

    (@codepeople)

    Excellent !!!!!

    Best regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Do while loop in calculated field’ is closed to new replies.