Answer to Question #245509 in C++ for Yoyo

Question #245509

Sometimes we want some part of our code to be executed more than once. We can repeat the code in our program. For example, we need to display our name for a hundred or more times it is not practical to write the same code. Which concept will be used? Explain it with the help of suitable example

 [5 marks]


1
Expert's answer
2021-10-02T02:58:58-0400

Loops can be used to execute a code more than once. A while or a for loop can execute a block of code many times provided a given condition is true.

#include<iostream>
using namespace std;
int main(){
	//This code will display My name is Abraham 100 times
	for(int i=0; i<100; i++){
		cout<<"My name is Abraham\n";
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS