Yubin Qiu Yubin Qiu - 5 months ago 21
Node.js Question

Javascript conditional logic nodejs

is it possible to do a checker for this scenario


  • An infinite loop of number, example 1 2 3 4 is coming into the server.

  • However I only want to accept these number once.



Here is what I have done so far. I think i am lacking of one more conditional check.

var check = false;

if(check == false)
{
check = true; // But once check is true the number will never come in
//For example, this will print 1. but it will not print 2 3 4.
//If i do not have the checker, it will print 1 2 3 4 1 2 3 4 1 2.. infinity time.


}





I have done an additional checker using loops to fix this issue

Answer

Do you know about the number of integers coming in a single loop? if yes, you can try something like this...

var counter=0;//outside the loop
var check = false;
var n=4;//no. of integers in single loop

if(check == false)
{  
     counter++;
     if(n==counter){
       check = true; 
     }

}
Comments