Complete the code to exit the loop immediately when i equals 3.
for (int i = 0; i < 5; i++) { if (i == 3) { [1]; } std::cout << i << std::endl; }
The break statement exits the loop immediately when the condition is met.
Complete the code to skip printing the number 2 inside the loop.
for (int i = 0; i < 5; i++) { if (i == 2) { [1]; } std::cout << i << std::endl; }
The continue statement skips the current loop iteration and moves to the next one.
Fix the error in the code to return from the function when x is negative.
void checkNumber(int x) {
if (x < 0) {
[1];
}
std::cout << "Number is non-negative" << std::endl;
}The return statement exits the function immediately.
Fill both blanks to create a loop that skips even numbers and stops when i reaches 7.
for (int i = 0; i < 10; i++) { if (i [1] 2 [2] 0) { continue; } if (i == 7) { break; } std::cout << i << std::endl; }
The condition i % 2 == 0 checks if i is even, and continue skips printing even numbers.
Fill all three blanks to create a function that returns the first positive number in an array or -1 if none found.
int firstPositive(int arr[], int size) {
for (int i = 0; i < size; i++) {
if (arr[[1]] [2] 0) {
[3] arr[i];
}
}
return -1;
}We check each element with arr[i] > 0 and use return to exit the function immediately with the first positive number.