@deng_cen please use tags to insert code into post. It is the hash"#" sign in toolbar above the text area for reply.
The continue statement, when executed in a while, for or do...while, skips remaining statements in the loop body and process with next iteration of the loop. In while and do...while statements, the program evaluates the loop-ontinuation test immidiately after the continue statement executes. In a for statement, the increment expression executes, then the program evalues the loop-continuation test.
I hate to look into Deitel&Deitel book to get you proper explanation to make it clear as I may get on rants to explain what the continue is for. In your case continue is not neccesary as you do not haveany commands after continue in your if/else checks so you can remove them. Example bellow will show when continue statement is usefull
for(int count =1; count <= 10; count++)
{
if(count == 5)
continue;
//this meessage will not be printed if count == 5
System.out.printf("%d", count);
}
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
So the way I have it. Is that ok?
as long you don't do it as the code from deng_cen shows you alright
if (result == 1) {// if result 1,
passes = passes + 1; // increment passes;
studentCounter = studentCounter + 1;
continue;
}
there is no reason for continue, no other commands in the if/else statement after continue
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
yes you have it there, appropriate increment inside if/else statement
if (result == 1) {// if result 1,
passes = passes + 1; // increment passes;
studentCounter = studentCounter + 1;
}
else if (result == 2) {// if result 2,
failures = failures + 1;
studentCounter = studentCounter + 1;
continue;
}
So studentCounter will be incremented only if the mark is 1 or 2
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902