Computer Science Canada Trouble with "for" statements and counted repetition. |
Author: | cellavb [ 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! |
Author: | TheGuardian001 [ 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
|
Author: | jbking [ 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 |
Author: | cellavb [ Wed Dec 16, 2009 8:28 pm ] |
Post subject: | Re: Trouble with "for" statements and counted repetition. |
Perfect! Thank you very much ![]() Now to tackle the homework ![]() |