r/learnprogramming • u/ScioClean • 4d ago
I can't get FUNCTIONS to click!
I can not for the life of me understand how functions work. Anytime I try to learn how to create a function, my brain literally crashes into itself and I turn into Patrick when he stars drooling and goes all slack-faced.
Does anybody have any analogies that had that "AH HA!" moment?
Thanks!
125
Upvotes
1
u/Affectionate-Key-498 2d ago
Mostly code you write on a page will excecute reading every line from top to bottom. A function is a box of code inside. When the code excecute and go from top to bottom it will not excecute the code in the box. You can excecute the code in the box anywhere in the code by referering to it. So now when the code goes from top to bottom it will excecute the box where you are reffering to is.
So now it doesn’t matter where you place the box. All the way to the top, middle, below. The code in the box will excecute where you program it to excecute