Please Give me an Answer on this.
(Write C++ program to print numbers 10 to 50 using for, while, do-while loop.)
Answers
Answer:
of while and do...while loops in C++ programming with the help of some examples.
In computer programming, loops are used to repeat a block of code.
For example, let's say we want to show a message 100 times. Then instead of writing the print statement 100 times, we can use a loop.
That was just a simple example; we can achieve much more efficiency and sophistication in our programs by making effective use of loops.
There are 3 types of loops in C++.
for loop
while loop
do...while loop
In the previous tutorial, we learned about the C++ for loop. Here, we are going to learn about while and do...while loops.
C++ while Loop
The syntax of the while loop is:
while (condition) { // body of the loop }
Here,
A while loop evaluates the condition
If the condition evaluates to true, the code inside the while loop is executed.
The condition is evaluated again.
This process continues until the condition is false.
When the condition evaluates to false, the loop terminates.