Looping Sstatements Interview Questions

    Question 1C++ For Loop Syntax

    Which of the following is the correct syntax of a for loop in C++?

    Question 2C++ Guess the Output – For Loop

    What will be the output of the following C++ code snippet?

    #include <iostream> using namespace std; int main() { for (int i = 1; i <= 5; i++) { cout << i << " "; } return 0; }

    Question 3C++ While Loop

    Which of the following statements about the while loop in C++ is true?

    Question 4C++ Guess the Output – While Loop

    What will be the output of the following C++ code snippet?

    #include <iostream> using namespace std; int main() { int i = 1; while (i < 4) { cout << i << " "; i++; } return 0; }

    Question 5C++ Do-While Loop

    Which of the following differentiates a do-while loop from a while loop?

    Question 6C++ Guess the Output – Do-While Loop

    What will be the output of the following C++ code snippet?

    #include <iostream> using namespace std; int main() { int i = 5; do { cout << i << " "; i++; } while (i < 5); return 0; }

    Question 7C++ Break Statement in Loops

    What does the break statement do in a C++ loop?

    Question 8C++ Guess the Output – Break

    What will be the output of the following C++ code snippet?

    #include <iostream> using namespace std; int main() { for (int i = 1; i <= 5; i++) { if (i == 3) break; cout << i << " "; } return 0; }

    Question 9C++ Continue Statement in Loops

    What is the effect of the continue statement inside a C++ loop?

    Question 10C++ Guess the Output – Continue

    What will be the output of the following C++ code snippet?

    #include <iostream> using namespace std; int main() { for (int i = 1; i <= 5; i++) { if (i == 3) continue; cout << i << " "; } return 0; }