Announcement

Collapse
No announcement yet.

Contruction of a loop

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Contruction of a loop

    Hi All,

    I am trying to build a loop that will return my code to a specific line
    number, what is the proper syntax.

    the line I am trying to write looks something like this.

    If (nRatioVal < 250) go back to line # 89;

    Ny help is greatly appreciated,

    Thanks,

    JD

  • #2
    JD
    In JavaScript which is the foundation of EFS you cannot loop back through lines of code.
    If the code in your line 89 is to be executed based on a single condition then you could set nRatioVal as a global variable and execute that section of code at the next iteration of the script prior to recalculating the variable nRatioVal (see first example below)
    If instead it needs to be executed multiple times based on different conditions then you could write it as a separate function and call it as necessary (see second example below)
    Alex

    PHP Code:
    var nRatioVal 0;
     
    function 
    main(){
     
        if(
    nRatioVal 250){
             
    //here you insert the code that needs to be executed
        
    }
     
        
    nRatioVal //code to compute this variable
     
        
    return;

    PHP Code:
    function main(){
     
        var 
    nRatioVal //code to compute this variable
        
        
    if(nRatioVal 250){
            
    doThis();
        }
     
        if(
    other condition){
            
    doThis();
        }
     
        return;
    }
     
    function 
    doThis(){
        
    //here you insert the code that needs to be executed

    Comment


    • #3
      Thanx Alix,

      Will the line of code after the If statement get continually executed until the 250 condition is met?? Or do you need
      a while loop???

      Does a while loop look like this??

      while (nRatioVal < 250) {
      execute this line of code;
      }

      What I am trying to do is to create an oscilator that will recalculate the data it is created on every time it reaches 150.
      The problem is that I am getting almost a straight line because it is getting recalculated almost every other tick or two.

      So, what I am trying to do is to create a condition that it must first
      reach 250 first, then when it goes to 150, recalculate the data and start the process all over again.

      I am assuming that by referencing the global function in the second if statement, that will start the process all over again
      by recalculating the data that creates the oscilator.

      Thanx again,

      JD

      Comment


      • #4
        JD
        For information on while loops see this page from the Core JavaScript Reference Guide which is available in the EFS KnowledgeBase
        In the case of your example the while loop would be written as follows
        PHP Code:
        while(nRatioVal<250){
            
        execute this line of code;
            
        nRatioVal++;

        For any more specific guidance you will need to post the efs you are using
        Alex

        Comment

        Working...
        X