When breaking a problem down, you often encounter elements that you want to use repeatedly in your code. Sometimes it's appropriate to write a new function; at other times it's appropriate to write a loop. There is no hard-and-fast rule as to which is better, but what do you think? What kinds of circumstances would lead you to writing a function versus using a loop?

Respuesta :

Answer:

FUNCTION:

  • A function does not require the number of times that the code script needs to be executed
  • When we go for large programming, ie. while creating projects, we can invoke function from one file to another based on the access specifier mentioned for the function.
  • There is a stack call created in the memory whenever a function is called.

LOOP :

  • Whereas the number of times that the loop has to be executed must be defined
  • A loop cannot be called, it can be used only the code block in which it is present.
  • There is not overhead of creating a stack since it is not invoked and there is no transfer of control from one module to another

Loops and functions are different elements of a programming language.

Loops

Loops are used to perform repetitive operations where each repetition is called an iteration,

In other words, a loop is a form of a code that needs to be repeated.

Note that a loop cannot be "called" or evoked.

Functions

A function is a collection of blocks of code that perform as one.

In other words, a function is a form of code that can be called or evoked , at any time.

A function is not better than a loop, and a loop is not better than a function because they are used for different purposes.

Read more about functions and loops at:

https://brainly.com/question/22500181