31.4k views
2 votes
What is the difference between a loop and a function?

2 Answers

13 votes
Simple definition
A loop is a code that will repeat again and again until the condition is true. If the condition become false the loop will stop executing.

A function is a code that will do a particular task when you call it. First you need to define a function which is known as function definition. And whenever you want to use it then you have to call the function.
If you don’t call the function then it will not work what you want.

Hope you like this
User Locket
by
4.4k points
0 votes
Big difference
Loops allow you to execute code multiple times while a condition is true
Functions allow you to “call” a snippet of code whenever you want, and you can pass it arguments that could affect the data it returns
User Urraka
by
4.5k points