Hello Dave,
do I understand your problem correctly: you don't know how to change while into for? If so:
Your main problem seems to know how for works:
- The first statement in for-instruction initializes the loop variable.
- The last statement rules how to finish a loop.
- The middle statement controls if a loop has to be started.
- Each of these statements can be empty (or extended to more than a single instruction).
Under these rules it works as follows:
- Starting the for-instruction, the initialization, i.e. the first statement, is done.
- The middle instruction is done, i.e.the framework controls whether the condition is fulfilled to do the first loop.
- The first loop is done.
- The final instruction, i.e. the last statement, is done.
- The middle instruction is done, i.e. the framework controls whether the condition is fulfilled to redo the loop.
- And so on...
You can change your while-instructions in this way:
for ( int i = 0; i <= 5; i++) {
for ( int j = 0; j <= 5; j++ ) {
itemp = i;
jtemp = j;
}
}
I hope this makes it a little bit clearer. Juergen
By the way, this is not a problem on #D, but on the language C# itself.