When function triggers, inside for loop number return default value again

Ryoush

I have a function inside a for loop. it's like;

function a(){
   var i=0;
   var endNumber= data.number;
   for(;i=!endNumber;i++){
      //doing stuff
   }
}

So, I want when function calls "i" value gets end of "i" value again. Because data.number always changes.

Hikmat G.

You can do something like this

let data = { number: 5 };

function a() {
  var i = 0;
  return function() {
    var endNumber = data.number;
    for (; i !== endNumber; i++) {
       console.log(i);
    }
    console.log('done');
  }
}

const func = a();

func();
data = { number: 10 };
func();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Is there optimization for constant function return value inside a loop?

From Dev

Return value for setTimeout function inside a for loop

From Dev

JavaScript closure triggers all inside the loop when registering OpenLayers event even with anonymous function or bind

From Dev

Function always return false when using .then() inside loop .each()

From Dev

When number reaches every nth value inside nested loop

From Dev

Can a function return the same value inside a loop, and return different values outside of loops?

From Dev

How do I break a loop inside the function and return a value for that function? (Javascript)

From Dev

Python function with default argument inside loop

From Dev

can a function return twice inside a for loop statement

From Dev

PHP function with for each loop inside - what to return?

From Dev

How to return a value inside of while loop

From Dev

how to return value inside of forEach loop in JavaScript

From Dev

node js - how do I return a value from a function when it depends on asynchronous function inside

From Dev

what is the default return value of a Dart function

From Dev

Python: return a default value if function or expression fails

From Dev

what is the default return value of a Dart function

From Dev

Python: return a default value if function or expression fails

From Dev

Function return only first output value by default

From Dev

Unable to return value from inside a function

From Dev

Get return value inside a function with javascript

From Dev

Access a controller function when inside a loop (ChildrenOf)

From Dev

Return a value from loop in recursive function

From Dev

recursive function with for loop: return value issue

From Dev

Get return value of function in a loop - shell script

From Dev

ruby function with loop return the wrong value

From Dev

My Python loop in a function is not running again when i call it again from another point

From Dev

Return a random number inside a loop in JS but never the same

From Dev

float value when past from a function is not same again

From Dev

how to return two maps value inside return function - react js

Related Related

  1. 1

    Is there optimization for constant function return value inside a loop?

  2. 2

    Return value for setTimeout function inside a for loop

  3. 3

    JavaScript closure triggers all inside the loop when registering OpenLayers event even with anonymous function or bind

  4. 4

    Function always return false when using .then() inside loop .each()

  5. 5

    When number reaches every nth value inside nested loop

  6. 6

    Can a function return the same value inside a loop, and return different values outside of loops?

  7. 7

    How do I break a loop inside the function and return a value for that function? (Javascript)

  8. 8

    Python function with default argument inside loop

  9. 9

    can a function return twice inside a for loop statement

  10. 10

    PHP function with for each loop inside - what to return?

  11. 11

    How to return a value inside of while loop

  12. 12

    how to return value inside of forEach loop in JavaScript

  13. 13

    node js - how do I return a value from a function when it depends on asynchronous function inside

  14. 14

    what is the default return value of a Dart function

  15. 15

    Python: return a default value if function or expression fails

  16. 16

    what is the default return value of a Dart function

  17. 17

    Python: return a default value if function or expression fails

  18. 18

    Function return only first output value by default

  19. 19

    Unable to return value from inside a function

  20. 20

    Get return value inside a function with javascript

  21. 21

    Access a controller function when inside a loop (ChildrenOf)

  22. 22

    Return a value from loop in recursive function

  23. 23

    recursive function with for loop: return value issue

  24. 24

    Get return value of function in a loop - shell script

  25. 25

    ruby function with loop return the wrong value

  26. 26

    My Python loop in a function is not running again when i call it again from another point

  27. 27

    Return a random number inside a loop in JS but never the same

  28. 28

    float value when past from a function is not same again

  29. 29

    how to return two maps value inside return function - react js

HotTag

Archive