Recall & Review
beginner Click to reveal answer
What is a jump statement in C++?
A jump statement is a command that causes the program to jump to another part of the code, changing the normal flow of execution.
beginner Click to reveal answer
Name the four main jump statements in C++.
The four main jump statements are: break, continue, return, and goto.
beginner Click to reveal answer
What does the
break statement do?The
break statement immediately exits the nearest enclosing loop or switch statement.beginner Click to reveal answer
How does the
continue statement affect a loop?The
continue statement skips the rest of the current loop iteration and moves to the next iteration.intermediate Click to reveal answer
Why should
goto be used carefully?goto can make code hard to read and debug because it jumps to any label, disrupting normal flow. Use it sparingly.Which jump statement immediately exits a loop or switch?
✗ Incorrect
The
break statement exits the nearest loop or switch immediately.What does the
continue statement do inside a loop?✗ Incorrect
continue skips the rest of the current iteration and starts the next one.Which jump statement returns control from a function to its caller?
✗ Incorrect
return ends the function and sends control back to the caller.What is a risk of using
goto in your code?✗ Incorrect
goto can jump anywhere, making code flow hard to understand.Which jump statement would you use to skip the rest of a loop iteration but continue looping?
✗ Incorrect
continue skips the current iteration and moves to the next one.Explain the purpose of each jump statement in C++ and give a simple example of when to use it.
Think about loops and functions.
You got /5 concepts.
Describe why using
goto can be problematic and what alternatives you might use instead.Consider how code flow is affected.
You got /3 concepts.
