CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

for loop question [DONE]

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
nilsener



Joined: 06 Dec 2005
Posts: 59

View user's profile Send private message

for loop question [DONE]
PostPosted: Wed Sep 03, 2008 2:35 am     Reply with quote

Dear,

i am always unsure if this loop will be executed 3 or 4 times?

Code:

for (i=1;i<4;i++);
{
Code
}


Thanks for help

Best Regards
nilsener


Last edited by nilsener on Wed Sep 03, 2008 4:50 am; edited 1 time in total
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

PostPosted: Wed Sep 03, 2008 3:05 am     Reply with quote

this will run for i=1 to i=3
So 3 times.

J
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
Ttelmah
Guest







PostPosted: Wed Sep 03, 2008 3:05 am     Reply with quote

The way 'for' executes is:
First the initialisation (i=1)

Then test - if false exit - don't execute body

Then loop body.

Then increment (i++)

Loop back to the test.

So, where the test applies, on the first pass, i=1, then i=2, then i=3 then i=4 - fail don't execute body.

So the body executes three times for the example as given.

Best Wishes
nilsener



Joined: 06 Dec 2005
Posts: 59

View user's profile Send private message

PostPosted: Wed Sep 03, 2008 4:50 am     Reply with quote

Thanks you very much for your answers, now I understand it.

Best Regads
nilsener
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group