Recall & Review
beginner
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.
Click to reveal answer
beginner
Name the four main jump statements in C++.
The four main jump statements are: break, continue, return, and goto.
Click to reveal answer
beginner
What does the
break statement do?The
break statement immediately exits the nearest enclosing loop or switch statement.Click to reveal answer
beginner
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.Click to reveal answer
intermediate
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.Click to reveal answer
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.