Is this the correct way to program a loop counter ?

 
Hello,

I wanted to know if this is the correct way to program a endless loop counter (see code below). Is it ok to initialize the static variable once at zero within the start function? I want the count variable to always start at zero and then count the number of times the infinite loop loops.

Thanks in advance. Much appreciated.


int start()
{
 
 
   while( IsStopped()==false )   // endless loop
   { 
   
   
       static int count = 0;
  
           Print( "Value of Count variable : ", count );
     
                count = count + 1;
             
   }

}


 
Yes.

count variable initialized once because this variable is static. Because there is endless loop start function will be called after next loading of EA only

In your case static int count=0 and int count=0 are the same
 
Yes.

count variable initialized once because this variable is static. Because there is endless loop start function will be called after next loading of EA only

In your case static int count=0 and int count=0 are the same


Thank you for this. However, I would have thought static int=0 and int=0 are "not" the same, as if use int=0 then count will always equal 1 and will therefore not count properly. This is because int=0 is initialized with zero each iteriation of endless loop. Do you agree with this?

Many thanks.

Regards

RJF
 
I see. You are right.

My remark applied to variable outside the loop
Reason: