Static voidMain (string[] args) {Console.WriteLine ("use break to exit a loop"); for(inti =0; I <5; i++) { if(i = =2) { Break; } Console.WriteLine (i); } Console.WriteLine ("use continue to exit a loop"); for(inti =0; I <5; i++) { if(i = =2) { Continue; } Console.WriteLine (i); } Console.WriteLine ("use return to exit the loop"); for(inti =0; I <5; i++) { if(i = =2) { return; } Console.WriteLine (i); } }
When the code is like this, the result is this:
Static voidMain (string[] args) {Console.WriteLine ("use return to exit the loop"); for(inti =0; I <5; i++) { if(i = =2) { return; } Console.WriteLine (i); } Console.WriteLine ("use break to exit a loop"); for(inti =0; I <5; i++) { if(i = =2) { Break; } Console.WriteLine (i); } Console.WriteLine ("use continue to exit a loop"); for(inti =0; I <5; i++) { if(i = =2) { Continue; } Console.WriteLine (i); } }
When the code is like this, the result is this:
The difference between C # break continue return