Core C++

Jump Statements

break


Video Tutorials

Lesson 27: Switch Statements

Example 1

// Using break in a switch statement
switch (iInteger) {
    case 0:
    {
        // Code to handle case 0
        break;
    }
    case 1:
    {
        // Code to handle case 1
        break;
    }
    default:
    {
        // Code to handle default case
    }
}

Example 2

// Using break to exit an inner loop
for (;;) {
    for (;;) {
        // Some code
        if (!bConditionForBreak) {
            break;
        }
        // Some code that might get skipped
    }
    // Jumps to this code if break is hit
}

return


Video Tutorials

Lesson 12: Basic Functions

Example 1

// A simple function which returns no value
void MyFunction() {
    // Some code
    return;
    // Some more code that might not get executed
}

Example 2

// A function which returns an int value
int MyFunction() {
    // Some code
    return iInteger;
    // Some more code that might not get executed
}

goto


Example 1

// This example jumps over a section of code
goto mylabel;
// Some skipped code
mylabel:
// Some more code

Example 2

// This example effective creates an infinite loop
beginloop:
    // loop internal code
goto beginloop;

continue


Example 1

// This example uses a for loop
for (int iIndex = 0; iIndex < 100; ++iIndex) {
    // Some code
    continue;
    // Some skipped code
}

Example 2

// This example uses a while loop
while (!bDone) {
    // Some code
    continue;
    // Some skipped code
}

Example 3

// This example uses a do-while loop
do {
    // Some code
    continue;
    // Some skipped code
} while (!bDone);
 

© 2007–2024 XoaX.net LLC. All rights reserved.