C++ program to demonstrate the use of break statement
gd.cpp
#include <iostream> using namespace std; int main() { for (int i = 0; i < 10; i++) { if (i == 5) { break; } cout<<i<<endl; } return 0; }
Output
godarda@gd:~$ g++ gd.cpp
godarda@gd:~$ ./a.out 0 1 2 3 4 godarda@gd:~$
C++ program to demonstrate the use of continue statement
gd.cpp
#include <iostream> using namespace std; int main() { for (int i = 0; i < 10; i++) { if (i == 5) { continue; } cout<<i<<endl; } return 0; }
Output
godarda@gd:~$ g++ gd.cpp
godarda@gd:~$ ./a.out 0 1 2 3 4 6 7 8 9 godarda@gd:~$
Comments and Reactions
What Next?
C++ Loops