Simple Explanation
Break: jump out of the loop and stop executing the loop body. Continue: end (skip) the loop and continue to execute the loop body.
Demo
/*breakDemo*/#include <iostream>using namespace std;int main(){for (int i=0; i<10; i++){cout << "i = " << i << endl;}cout << "break..." << endl;for (int i=0; i<10; i++){if (i == 5){break;} else{cout << "i = " << i << endl;}}}
/*continueDemo*/#include <iostream>using namespace std;int main(){for (int i=0; i<10; i++){cout << "i = " << i << endl;}cout << "continue..." << endl;for (int i=0; i<10; i++){if (i == 5){continue;} else{cout << "i = " << i << endl;}}}
Images and truth
/*breakDemo*/
/*continueDemo*/
Of course, the results in Java are the same.
/*** Created with intellij idea. * User: Happy * Date: 13-7-29 * Time: * to change this template use file | Settings | file templates. */public class continuedemo {public static void main (string [] ARGs) {for (INT I = 0; I <10; I ++) {system. out. print ("I =" + I + "\ t");} system. out. println ("\ nbreak... "); For (INT I = 0; I <10; I ++) {if (I = 5) {break;} else {system. out. print ("I =" + I + "\ t") ;}} system. out. println ("\ ncontinue... "); For (INT I = 0; I <10; I ++) {if (I = 5) {continue;} else {system. out. print ("I =" + I + "\ t ");}}}}