Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Trouble with "for" statements and counted repetition.
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
cellavb




PostPosted: Wed Dec 16, 2009 7:58 pm   Post subject: Trouble with "for" statements and counted repetition.

Hello all, I'm fairly new to both Compsci and C++ itself, but I was hoping for some help, please.
I am currently in computer sciences intro. but after breezing through Turing, C++ has got me stumped.

For a project we are working on, I need to write a statement of counted repetition (like the "for" statements in Turing).
Its very simple, just reciting numbers from x to y or y to x, with different increasing and decreasing rates.

All my resources are showing nothing though, how are these statements set up and worded in the C++ language?

Help is much appreciated!
Sponsor
Sponsor
Sponsor
sponsor
TheGuardian001




PostPosted: Wed Dec 16, 2009 8:18 pm   Post subject: Re: Trouble with "for" statements and counted repetition.

the syntax is for (initial value;continue condition;increment), IE

code:

for (int i = 0; i < 10; i++){}
jbking




PostPosted: Wed Dec 16, 2009 8:20 pm   Post subject: Re: Trouble with "for" statements and counted repetition.

From MSDN:

Quote:
for ( init-expression ; cond-expression ; loop-expression )
statement


Where:

"init-expression" is the initial expression to start the loop, e.g. int counter = x would be if you wanted to create an integer variable initialized to x.
"cond-expression" is the conditional expression to determine if the loop should repeat, e.g. counter < y would be if you wanted counter to be less than y while the loop runs.
"loop-expression" is what gets executed each time the loop code runs,e.g. counter=counter+1 or counter++ would be a couple of ways to increment the counter by 1 each run.
"statement" is a block that runs in the loop
cellavb




PostPosted: Wed Dec 16, 2009 8:28 pm   Post subject: Re: Trouble with "for" statements and counted repetition.

Perfect!
Thank you very much Very Happy
Now to tackle the homework BooHoo
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: