Question #245678

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


Expert's answer

It's loops. Example:

prints 10 times "Hello!"

for (int i = 0; i < 10; i++) {
	printf("Hello!\n);
}

Other constructions:

  • while(condition) {}
  • do {} while (condition);
LATEST TUTORIALS
APPROVED BY CLIENTS