Declare a counter variable i and rewrite the for loop header using the operators for the counter class. |
According to that, there is a counter class, which, according to you, you have no other code. So, I'm going to just assume your teacher want's you to use an integer, or int.
However, if that's the case, your teacher has essentially already given you how to write a proper for loop.
for (int i = 0; i < n; i++)
It says to rewrite it, but doesn't say how. If they want a for loop version of it, just use the same code, but change n to some value. If they want you to break apart the for loop into something that works the same way, refer to my code I pasted earlier.
Essentially, a for loop is a sophisticated while loop. Observe:
for ( /* Declaration */ ; /* Condition */ ; /* Repetition */ )
Translates to:
1 2 3 4 5
|
/* Declaration */ ;
while ( /* Condition */ ) {
/* Repetition */ ;
}
|
I can't just write your answer for you, but if you closely at where each part fits from the for loop structure to the while loop structure, I'm sure you'll get the right answer.
Edit: Presuming this is related to your other question, I assume counter is either a pseudo class, or one that you have been studying about but haven't shared the information, possibly because you don't know what to share. However, much like your other post, I'll take a stab in the dark about how to create a for loop with this unknown Counter class.
for (Counter myCounter = 0; !myCounter.atMax(); myCounter ++)
Either this, the first one I posted above, or some slight modification of either should be the right answer based on the context of what I've been reading from your posts. I assume these are homework questions for end of term that you either didn't do or are trying to cram in at the last minute. Either way, you should try to complete these kinds of problems when you're actually learning about them, either in class or out of the book.