Jump statements

Jump statements are used to transfer control from one point to another point in the program using some specified code while executing the program. In simple terms, while using jump statement control will jump from one point to another point. There are four keywords in the Jump Statements. we'll see all those with its definition below.

CODE

EG 1 . Login application using Goto statement

#include <iostream>
using namespace std;
int main() {
    Start:
    string username, password;
    cout << "Enter Username : ";
    cin >> username;
    cout << "Enter Password : ";
    cin >> password;

    switch (username == "info@coderscapsule.com" && password =="123456789") {
        case true:
        cout << "You have unlocked your phone!!!" << endl;
        break;
        case false:
        cout << "Invalid Username/Password" << endl;
        break;
    }
    goto Start;
}



EG 2 . Login application using break statement

#include <iostream>
using namespace std;
int main() {
    string username, password;
    cout << "Enter Username : ";
    cin >> username;
    cout << "Enter Password : ";
    cin >> password;

    switch (username == "info@coderscapsule.com" && password =="123456789") {
        case true:
        cout << "You have unlocked your phone!!!" << endl;
        break;
        case false:
        cout << "Invalid Username/Password" << endl;
        break;
    }
}



EG 3 . Creating For loop using continue keyword

#include <iostream>
using namespace std;
int main() {
    for (int i = 1; i <= 5; i++) {
    // if the value of i becomes 3, system will skip 3 and send the transfer to the for loop and continue with 4
    if (i == 3) {
        continue;
    }
    cout << i << endl;
}




(Click Here, For more exercises)