You forgot to add "
Complete C++ course
[
Break, continue and goto statement
In a paragraph :
Goto statement :
#include <iostream>
using namespace std;
int main() {
int n = 10;
int target = 5;
for (int i = 0; i < n; i++) {
cout << Iteration " << i << "\n";
if (i == target) {
goto end;
}
}
end:
cout << "Loop ended at iteration " << target << "\n";
return 0;
}
change :
#include <iostream>
using namespace std;
int main() {
int n = 10;
int target = 5;
for (int i = 0; i < n; i++) {
cout << "Iteration " << i << "\n";
if (i == target) {
goto end;
}
}
end:
cout << "Loop ended at iteration " << target << "\n";
return 0;
}