why does this for loop not work?

 

Dear all

 

Would you please tell me how to fix it?

 

      int k2=10000, k3=1000, TimeFrame2=60;

      for( int i=k2; i>k3; i-TimeFrame2*60 )
      { Alert("i= "+i); }

 

Thanks a lot!

 

wing 

 
wing:

Dear all

 Would you please tell me how to fix it?

Read the documentation about for loops . . .

Expression1; while(Expression2) { operator; Expression3; };

 

int k2=10000, k3=1000, TimeFrame2=60;

int i = 10000; 
while(i > 1000)   
   {
   Alert("i= "+i);

   i - 60 * 60;   //  what does this do ? ?  did you mean i -= TimeFrame2 * 60  ?
   }
 
deVries:

what result did you expected ???


it should issue alert message on screen:

 

i= 10000

i=  6400

i=  2800

i=  -800 

 
RaptorUK:

Read the documentation about for loops . . .

Expression1; while(Expression2) { operator; Expression3; };

 


I did read the document.

 

my problem is, when I compile it, "it seems" editor only allow coders to use i-- or i++ in expression 3.  Even I used "i-2", it didn't accept.

 

I would like to know if my observation is true or I miss something in the rule. 

 
wing:


it should issue alert message on screen:

 

i= 10000

i=  6400

i=  2800

i=  -800 


  for( int i=10000; i>1000; i=i-60*60 )
      { Alert("i= "+i); }

will  give outcome 10000   6400  and 2800

not -800   because it is lower then 1000 

to get your result ......

 for( int i=10000; i>1000; i=i-60*60 )
      { Alert("i= "+i); }
 Alert("last alert i= "+i);

 or like

int i = 10000;
 Alert("i= "+i);
while(i > 1000)   
   {
   i=i - 60 * 60;
   Alert("i= "+i);
   }

 you can write it this way

 
deVries:

will  give outcome 10000   6400  and 2800

not -800   because it is lower then 1000 


ok, I get it!

 

thank you so much! 

Reason: