Functions

3 minutes
Share the link to this page
Copied
  Completed
Learn about the wonderful world of functions to help create reusable and tidy code.

Transcript

Hello, welcome to the 16th tutorial on the swift programming theories. And in this problem functions function basically allow code to be grouped together and only run when the function is called the function can also be called several times, which is pretty cool. And here we're just going to implement a simple example of a function. Open this up. What we're going to do is just the funk that's the keyword, the function that's going to call it print functional. This is going to print a line, print.

And then we're gonna put cause something really, really simple. I'm gonna do var o equals eight and I equals eight. And the function will record and call the function you've specified function name. And then you put all control brackets. In the next tutorial, we're going to look at function parameters, which go within here. And if the function has parameters, then you need to specify a value flow parameters.

But as the function doesn't weakness, call it like this. So if you run it, it has the print line, that's a function of encoding nothing. Okay, I could have just done this one, print nine. But the thing is, if I want to call several times and what if there's quite a lot going on here, or maybe some sort of custom mathematical function, I don't have to be repeating that complex code over and over again and you've got it working. And when you copy and paste in a Oh, you wrote in the several times the the human tendency to make mistakes when you do it several times. So doing it in a function is good simply Part One thing to note is you need to have the function declared and implemented for you calling this I fight for it after this if dammit I'm gonna get billed fail because he's a long resolver lead five print function hit the neck resist essentially along for this basically is the same as the variable forward to put oh yeah you'll say no to them exist and finally it wasn't it wasn't declared and implemented until after he was essentially youth so that's it for this tutorial the next tutorial we're gonna look at function parameters.

If you have any questions feel free to message us or support us on a system that clearly Okay, the email will be in the description and comment on the on this video or directly messaged us via YouTube or All the requirement for source code will also in the description. Thank you for watching and have a nice day.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.