Here it is
using System;
class forDemo {
static void Main () {
int i, j;
bool done = false;
for(i = 0; j = 100; !done; i++, j--) {
if(i*i >= j) done = true;
Console.WriteLine("i, j: " + i + " " + j);
I just don't know how this code works. For my understanding, done is initialized to be false at the start up of the program, but when it comes or enters into the FOR loop, since !done, which means done is not false(because ! = NOT), that means it is true, so the program runs. The conditional expression determines if the FOR loop will continue and if the conditional expression, which is done in the middle of the FOR loop, is false, there is no way that the block of the statements within the body of the FOR loop will continue and the iteration will never takes place. BUT I JUST DON'T UNDERSTAND WHY in the middle of the if(i*i >= j) done = true, why do we have to set done = true and what does it do in there?

New Topic/Question
Reply




MultiQuote







|