What Is The Output Of The Following Code Segment? N = 1; While (N <= 5) Cout << N << ' '; N++;?
What Is The Output Of The Following Code Segment? N = 1; While (N <= 5) Cout << N << ' '; N++;?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What Is the Output of The Following Code Segment? N = 1; While (N <= 5) Cout << N << ‘ ‘; N++;
Answer: The correct answer to the following code when it is executed is option 5.
The purpose to use loops is to repeat the code. Such as if you want to display the message 10 times then instead to write it over and over you can take help from the loops. Loops are efficient and also enhance the program efficient. Three types of loops exist which are listed below:
While loop:
While loop work by determining the given condition, and it is true the while loop body code is executed. The condition was checked again till it was false, after that the loop terminated.
The while loop syntax is:
While (condition) {
Loop body
}
do While:
It is the extension of the while loop and the major difference is that in it the loop is executed and then the condition checked, which is the opposite of the while loop. The syntax of the do-while loop is :
Do {
Loop body
}
While (condition);
So do while work in the following way:
For loop:
For loop is considered as the repetitive loop which permits you to write it when you need to execute it for a specific time. The syntax of the for loop is:
For (i=; i<= condition; i++) {
Body of loop
}
It works in the following order: