Learn Swift in one Video easy tutorial for beginners | Derek Banas | Skillshare

Learn Swift in one Video easy tutorial for beginners

Derek Banas, Web developer , Entrepreneur , Teacher

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
2 Lessons (1h 10m)
    • 1. Course Intro

      0:26
    • 2. Swift Tutorial for beginners

      69:34

About This Class

Start Developing iOS Apps (Swift) is the perfect starting point for learning to create apps that run on iPhone and iPad. View this set of incremental lessons as a guided introduction to building your first app—including the tools, major concepts, and best practices that will ease your path. Each lesson contains a tutorial and the conceptual information you need to complete it.

The lessons build on each other, walking you through a step-by-step process of creating a simple, real-world iOS app. As you make your way through the lessons and build the app, you’ll learn about concepts in iOS app development, gain a deeper understanding of the Swift programming language, and familiarize yourself with the many valuable features of Xcode, Apple’s integrated development environment (IDE). Prerequisites

Today I'll help you learn Swift in one video! All of the code follows the video below. We'll cover Data Types, Casting, If, Ternary Operator, Switch, Range, Arrays, Tuples, Dictionaries, For, While, Functions, Variadic Parameters, Pointers, Inner Functions, Closures, Structs, Computed Properties, Static, Classes, Objects, Overloading, Inheritance, Dynamic Typing, Protocols, Extensions, Generics, Enums and more.

To download the latest version of Xcode Open the App Store app on your Mac (by default it’s in the Dock). In the search field in the top-right corner, type Xcode and press the Return key. The Xcode app shows up as the first search result. Click Get and then click Install App. Enter your Apple ID and password when prompted. Xcode is downloaded into your /Applications directory.

Let’s get started!

Transcripts

1. Course Intro: 2. Swift Tutorial for beginners: we'll allow Internet and welcome to my swift video to Tora. You guys requested it. And here it is in this one video minute, pretty much teach everything you want to know about the swift programming language we're gonna be covering data types, math condition, ALS arrays, dictionaries to pols, looping functions, closures, struck's classes, protocols, extensions, generics, Denham's and a whole bunch more. And to help you get to exactly whatever you want to learn, rather than watch the entire video in the description underneath the video, you're going to find lists of every single topic that I cover in this whole to Touro. And you can click on those and jump directly their toe, learn whatever you'd like to learn. And I have a whole lot to Dio. So let's get into it. Okay, so I'm gonna be using X code in the suit. Theron, I'm just gonna skip this part here, and I'm gonna come over here to open our file and go file new and go file. This is going to open up and I'm gonna click on IOS and source and playground and click on next. Now it's gonna ask me to create something we could just call this my playground doesn't really matter. Click on create. And if it says, Do you want to replace the sea, I'll say replace. And this is basically what you should see on your screen. Of course, your phones aren't gonna be as big as mine. What I want to do also, however, is this is the playground area right here, which is going to print out everything on the screen. I'm going to instead use what they call the assistant editor. And you just go view assistant editor and show assistant editor. You can see here you can put it on the right bottom, horizontal or vertical. I'm gonna say I want to write. And over here is where all of the output for our program is going to show over here on the right side of the screen. They could see right here. This is a basic one line comment, and I'm gonna go through everything. And here is a multi line comments. Pretty simple, pretty much like every other programming language you may have seen. See here where it says you I kit. This is for developing IOS applications and those, or for the U I part of that, I'm also gonna commit here and import another library called Darwin. And this is going to contain a whole bunch of C libraries that we're gonna want to use and basically right here, what we're doing is creating a variable. Now you see here where it says var. That means that this is a variable value that can be changed if we typed in, let instead that would be a constant, a little bit strange. But that's the rule, and that's the way it goes. Now you're variable names must start with a letter. However, they can contain most any Unicode character except for whitespace mathematical symbols or arrows. Now, if you do not provide information in regards to what exactly this is in this situation, it would be a string. And that's how we would define a string by putting the colon and the data type right there . And I'll go through all the other day, different data types. But if you didn't put that, their swift is going to use type inference to guess the data type based off of whatever, Daddy, you were going to be storing it, so this would be a string, whether this was here or not, but I personally like to define the data types for everything. Another thing that's important to know is even though remember, we change this div are instead of let, so that means we can change the value here. That doesn't, however, mean weaken. Go in here and then jump in and say, str is equal to one that would be an integer and you see over here gives errors and it says cannot assign value of type end to a value of type string. Say it knew it was a strength, So it does use data types and will keep you from entering certain data in there. But that's just the way it is, all right, so let's create a constant just we can put this on the screen so I'll go pies equal to That's a constant and this is not a constant. If we would like to print screen, we could go print line like this and then inside of here, we could say pie is equal to, and then if we wanted to insert the value of pie inside of there, we put a backslash and then we put whatever the variables name is inside of there, and you can see over here in the output window that is printing all that out for us. And of course, we could also come in here and specify the data type. So say we wanted to track the number of steps that we had. We would just put a colon and upper case and like that is equal to and we'll just put 450 in there just to put something in. And the different data types that are going to be available for us are going to be ence. Which, of course, are going to be imagers, doubles or floats, which, of course, are going to be floating point numbers or numbers with decimal places. Strings, of course, which is just a whole bunch of characters between quotes Bull, which are going to be bully ins. And then there's characters a whole bunch of the different types of will also get into here in a second. Now, of course, like any other programming language, there's going to be limits in regards to the size that they're going to be able to hold. And if we're an integer that size would be equal to that gigantic number right there. However, you could actually store a bigger number. Let's say that we would go Max unsigned if we throw out the sign part of our variable and how we would get that. But maximum value is we would go you into 64. That's an unsigned 64 bit number. And then we could Dio you end 64 Max like that. And that is how we would sort that. Also, you may have noticed there's no semicolons and swift. If we did this, we could then go print line and then we could go Max unsigned. You only need to back slash and all of that. If you are going to be printing out everything inside of quotes, and in that situation you can see the maximum unsigned int that we can use inside of Swift , another massive number. You could also find the maximum float value just by typing in backslash and put that bracket there F L C max and it make sure you close this off and the maximum double changes to double and then type in double max and you could see over here exactly the maximum sizes for the floats as well as the doubles. It is very important to know that there are precision issues inside of Swift, just like everything else. You're basically going toe, have accuracy to six digits, and we could test that out if we would go and create a float in the situations at one point and then throw in a whole bunch of nines or six nines and then plus and 0.123456 and then five at the end there and then have it going and print the difference. And you're going to see right there that it actually converts that to. So there are only accuracy in regards to floats up to six digits, nothing more. And you're going to see that with doubles, they're going to be precise up to 15 digits, and we contest that out by coming over here and looking at this, you can see it also went up to two. However, if we take out one of these numbers, we're going to see that we have accuracy. So for floats, you're going to have accuracy to six digits and doubles. You're going tohave precision up to 15 digits in regards to your floating point numbers or your decimals. Bull Ian's, which are created with BOOL, are going to store either true or false, so it could create. One is over 18 and we're going to assign a value of true. There's your boli in your strings, like I saw before are going Teoh store a whole bunch of different types of characters between quotes. You're going to be able to combine your strings or can Captain Eighth. Um, by just doing something like my name is, there's your quotes. Put a plus sign in there and you could put in my name and just remember that whenever we used let here that stripped in this string in this situation is going to be immutable, which means that it cannot be changed. And you could see if I went in here and got statement and then tried to add an exclamation mark at the end of it. Right like that, we're going to get in there. Whoever If I change that to var, you're going to see that that error went away. Okay, so now let's talk about casting, which is just converting from one data type into another. And in this situation, if we would want to cast a float into an integer, we could just tape in end and then our brackets and then whatever we want to convert into an imager just like that, very simple. If we then wanted to come in here and convert an imager into afloat and just pay attention that the ends and the floats are all uppercase, we would just come in here and instead type in float. And then, of course, we'd have to put in some type of integer value inside of there. And yes, indeed, we could also come in here and convert different things into bully ins, and we would just type in full again, and this would convert the maximum imager into a bowl. Ian. And you can see over here exactly how those work and pretty much anything except for zero is going to result for true in regards to bully ins. If you'd like to turn a string into an imager, go let my age now, of course, it's gonna have to already be a number, but we're defining this right now as a string, and if we would want to convert it into an integer my age and my age and then to end right like that. And now, if you'd like to convert a string in tow afloat, we could just go my age floats and then you go my age as an s string. This is something you kind of have to remember and then follow that with float value. That's pretty much all you need to know about casting and converting into different data types. Let's take a look at the different math functions that are available to us. I just went ahead and did these all ahead of time and you could see here exactly. We can, of course, add, subtract, multiply. Divide this. However, rather than being called the module, ISS is known as the remainder operator inside of Swift. And the reason why is normally, whenever you would dio 5.3 divided by three with the module issued, get an answer of two is a remainder. In this situation, you actually get 2.3. So that's just something. Pay attention to along with these math functions, there's a whole bunch of different shorthand notations that we can have here, so it's just created imager. Now if we would come in and go numb plus plus, which is shorthand notation for add one to whatever numb is going to see here that you may get results that you're not expecting. So we'll go numb plus plus right like this. And if we take that in here, seen, um, has a value of one. However, one of we come over here, you see that it has a value of one. Wait a minute, I thought we added one to it. Well, the reason why it shows up that way is because whenever you put the plus plus after or the plus plus after right here, what it's actually doing is getting the current value of Nome putting that in there, which is one. And then after it leaves the print line statement it then adds one to this, and you're going to see here if we put in plus plus and get rid of this instead, this does the absolute opposite. It first adds one to the value and then prints it out for the screen. And that's the reason why it has a value of three instead of one. There's also shorthand notations known as compound assignments and you can see right there all of those and all this is going to do is it's going to take five and then add it to whatever the current value of Nome is, and then save it back to the variable Numb. You could see her here. How all the results workout here for you. And of course, we're gonna be able to do this with plus minus multiplication division as well as the remainder operator. And there's a whole bunch of different math functions that are available. And that's one of the only things I'm not going to cover in this detour, all the different libraries, because literally, there's no end to them. But I think it would be very important to come in here and talk a little bit about the random number generator. If you'd like to generate a random number, you're just going to come in here and you're gonna tape in arq four random right like this , and then the maximum number you want to generate between zero and but not including this. This basically just means I want to generate a random number between zero and 10 c. One less than whatever you put inside of there. And here you can see the random number generator. It is zero. And if we change that, you're going to see a new random numbers generated and we could change it back and you're going to see that it generates another random number. Now let's take a look at condition ALS now the conditional operators that we have available to us, they're going to be greater than less than greater than or equal to less than or equal to equal to and not equal toe. And the logical operators were going to have available are and or and not knowing to go in here and show you exactly how they work. And also take a look at ifs, else's and else ifs and all that stuff. Let's come in here and let's create a constant for age making an integer and give it the value of 13. We can then do some different tests here, so we could say if age is less than 16 in this situation, we could say you can go to school and then we're going to be able to do another conditional statement saying else if and yes we can use brackets we'd like to, and let's use a logical operator as well. We'll say if age is greater than or equal to 16 and which means the only way this is gonna come back is true is if both these statements come back. It's true. Age is less than 18. In that situation, We're going to say you can drive And then, of course, as a final default value or final default action, we're gonna be able to come in here and say You can vote and use the else statement. So if it goes through this condition in this condition, this condition is definitely going to be handled right like that. The other logical operator I'd like to take a look at is or so we could say, if age is less than 14 or this just means that either one of these convey be true and it would come back as a positive reaction, and we could say something like, You shouldn't work something like that. And then finally we could take a look at, not and how that works. It's just basically going to give you the opposite of whatever you give it, so in this situation. If we go not true, then we could just come in here. You can see that that comes back, it's false and you can also see the results of our other. If then else statements. The thing that we have available is what's called the Turn Eri operator, which is basically going to have a condition and then sign a value based off of that condition. So I will say is legal to vote and will create a bullion and this could be anything. It doesn't have to be a bullion and will say if age is greater than 18 then we're gonna put a question mark in. And if this condition right here comes back is true, we're going to assign a value of true to this bullying called is legal to vote. Otherwise we're going to assign false right here. And just like I said, this doesn't have to be a bully in this could be an integer and you could tape in some other number here 12 and 18 it doesn't matter. It's just a just a way of using the turning operator. And just the gist of understanding of this is based off this condition, this value right here. This variable is going to either be assigned this value if it's true or this value if its walls. And that brings us to another way of testing condition, ALS, and that is going to be the switch statement. Now the switch statement and swift, unlike many other languages, is going to work within its doubles floats, bullion, strings and a whole bunch other different things. So let's just say we have a program here that is going to make suggestions based off of ingredients that you have available. So let's just say we have pinto beans as our ingredient. We can then go switch and then we're going to check the value of this guy and then perform different actions based off of whatever that value could bay. So we could say if the value of the ingredients is equal to pasta or tomato, put a colon right there. In that situation, we could make the recommendation of saying, How about spaghetti now by default? Unlike most languages, whenever you hit a condition and that comes out is true and you perform the actions here, we are normally in swift goingto leave the entire switch statement in other languages. You would actually fall to the next case statement unless you put a break in here. Switch doesn't work that way. Which works the opposite way inside off. Swift. Sorry about that. So in this situation, if we would actually want to check the other ingredients, we would have to type fall through right here. So what it would do in this situation with fall through here is if we had case potato, this wouldn't actually happen. But what it's going to do here since falters here, even if ingredients had a value of paste like this, actually, this should be pasta. Even if this had a value of pasta meaning ingredients. Since fall through us here, it's going to come down and check to make sure that it also doesn't equal potato. And judge just is the way that Swift works. It decides that it in most situations were not gonna want to say in the switch statement in situations which we do, we want to put fall through right here. Otherwise, it's just going to leave assumes that hits match, and in a situation we could say, How about a baked potato and then finally to match. Exactly the results that we have here will say Pinto beans and we'll just say burrito. And also you're going to have a default option with a switch statement and this is what's going to be triggered if nothing else hits. And in this situation, we're going to say something like I don't know. So that's how switch statements work. Demise will go in here and show you another situation which we can use switch statements which statements? Air pretty powerful inside of Swift, we could use something else called a range. What I'm gonna do here is just committed and go Let meaning this is gonna be a constant and will use a test score here, and we'll give it a value of 89 just to put something in there. Now what Weaken Dio is Come in and go test score. And we could actually come in here and say, Case, let's say we wanted to track from 93 123 toe 100 as a potential value for the test score. And in this situation, we could say we could then continue to go 85 123 and this would allow us to test a range of potential values that we would have here. And of course, all the code that I have here is available in a Lincoln description, and we could continue going on and on and on until we got to a default value and in that situation would say something like, You got enough? You can see that it's pretty powerful. Now let's take a look at a raise. Really. The only rule you need to know about a raise is whenever you're going to be storing data inside of them, they have to be of the same type, and we're going to be able to make a raise, a type Ence floats, double strings, bowl Ian's as well as just pretty much any type of object which will get into here in a second. We can create an array in a couple different ways. We could go in here and say we want to have an array of friends, and array is just a bunch of boxes that contain data, and each one of those boxes gonna have a label or what is more commonly known as as an index. The first index or the first value inside of an array is going to have the index zero and it's just going to continue going. 12345 Sure, if you've seen other languages, you know exactly how that works. And here we're going to create a string array and then we can go in place values inside of it one of were initializing this. So let's just say we go, Bob. And that is how easy it is to create that. However, we could also have Swift go in here and automatically figure out the data type for us. And that will work in most situations So we could go 36 and nine and know that that's gonna create the proper imager, right? Like I said, we're going to be able to reference these different values based off of using indexes so we'll say ran numb one. If we want to get the first value that is stored inside of our Rann Na Marais, just go Rand gnomes in the first value is going to have the index of zero you could see right here it shows up and there's three and you can see right there there is three, we could also come in and create empty arrays. Of course, you're gonna want to start those off with VAR because otherwise it would basically just be worthless. And in that situation, we're going to say that we wanna have a string around and put these two parentheses there. And there you go. You just created an empty array that is going to hold strings. Now that you have this empty array, you're going to want to add values to it. And you're gonna want to do that with upend. Let's say one to come in here and type in tomato and let's throw a couple other different things in order groceries, array. We could then find out how many different items we have stored inside of this around print line and print line at what it does is it basically prints out everything that is in between the quotes and then puts a new line at the end of it. You could also use print, and that would do exactly the same thing, except it would not put a new line after it out. Put it everything on the screen. So there's that. Also, it's a numb of groceries. And then, if we wanted to get the number of groceries, we just go groceries dot count and you could see number of groceries comes back. It's three. We would then be able to come in here and insert an item at a specific instance or index, but it's by just going groceries insert. Let's say we want to put flower inside of here and put it at index number one. That's going to do that. It makes a lot of sense. Come in here and print groceries, then to see exactly how this is gonna change it, and you could see right there. Index one. Remember, this is index zero. It's going to insert it at Index one, and then it's going to move over rather than deleting what was previously inside of index one. If we would want to replace an item, we would just go groceries and then reference whatever the indexes that we wanted to replace. So let's say we want to be healthy and we want to eat whole wheat rather than regular old flower. We could do that like that, and you could see flowers been replaced with whole wheat flour. We could also come in and remove an item groceries, remove at index and then let's type in zero here. Maybe we decided that we no longer wanna have tomatoes and you can see that that's been moved and all the other different parts have all been moved over to the left. We could also come in and remove an item by its value. So let's say we go. If let's match is equal to And we could say that we want to find inside of the groceries array the value of beans. And then whenever we find it, we wanna go groceries, remove at index and then get on match, and that is going to cut beans out of our array. Gonna be able to sort the array pretty easily in neat way is sort of. So go groceries is equal to sorted, and then you're gonna type in groceries like this, and if you want to go from lowest to highest, you go less than otherwise. You would do greater than you can see. Sword it potato, whole wheat flour. You could also, in a very similar way, go groceries reverse to reverse every single thing that's inside of the Iran. And yes, we can also create a raise inside of a raise or multidimensional raise. Weaken Go Array. Let's say we want to put in array inside of an array only just go like this instead of one brackets. We're gonna put two inside of there and then we could go in and assigned the different values. So we're gonna have our one big array and our Ray inside of a race. Let's put it 00 So we'll be ableto maybe a little bit easier, be able to see exactly what's inside of here. And I just went through those into strings changes from into string to make a string courageous so that we keep this being 00 in instead of just switching into regular zero. And I'm setting this up so that we basically see that the first integer array or first string array is first going to increment the columns going down, and then the 2nd 1 is going to increment the rose going across and will be able to cycle through these using a four loop. We'll get more into four loops here in a second, but basically what we're saying here is we want to cycle through these columns in our array in our array, which is the name we have here for it. As long as columns exist and then we can say for row in column. We cycle through all of the columns or the rose. As long as they exist in our column, it will be able to go print line and then, of course, output. Whatever the value is for our Rome as well as the value for our column. If we close that off, you're going to see that it went out and printed all of that information out on our screen . That's a brief explanation of exactly how raise work as we go on. We're gonna be looking at them a little bit more now. Let's look at something very similar, which is called a dictionary. A dictionary is very similar in a right, except it's gonna hold key value pairs, and the key is basically going to be the same thing as the index with the Rays. However, instead of just be using zero through 12345 and so forth and so on, we're gonna be able to use editors double strings or even e numbs, which we're gonna look at here in a moment. No, let's create a dictionary and we'll just go for superheroes and camel cases very commonly used whenever we generate or define our variable names. Then we're going to say, What do we want? The data type for our key to be as well as the actual data that we're gonna be storing inside of here. And that's how we create a dictionary. And then we can come in and add in values by just going superheroes and then providing whatever we want. The key name to bay. I'm gonna make this Superman and then we can assign whatever we want the value today, right like that. We can then check how many heroes we have stored inside of our dictionary using count, just like we did with a raise. Superheroes count. You can see the output. There just shows us one, and we'll also be able to come in here and remove items by just referencing the dictionary by name again removed value four and then type in whatever the key name is for the thing that we want tohave deleted. There's a rough overview of exactly how dictionaries work. Now let's take a look at two pools now two polls air normally used When you want to be able to return many values from a function all at once, you can store a whole bunch of different values inside of A to pull and then return it all at one time where you would normally only be able to return one value at a time. And we're gonna look more in that. And how we're going to create a to pull is, let's say I want to have height. I can define that as 65 wait Wants to find that as 1 79 and name. And let's assign this to mine. In there you go. Just created a to pull. We're gonna be able to go in here and get the value just by referencing the two poles name and then whatever type of data we want to pull out. And of course, we could do the same thing for weight and name. That's just the basic gist of how to pull works. And like I said, I'm gonna give you mawr examples of two poles using real world experiments as we go on, but I have to cover a couple other different things before I can get into those examples. And one of those things that is very important are four loops talked about them a second ago. Basically, what I'm gonna do here is I'm going to create a value here that is going to increase in value, and it is eventually going to throw us out of the four loop. What we're going to say is, we want to continue cycling or executing code as long as I is less than or equal to 10 and then we're going to increment the value of I. Let's think about what we could do here. Let's say I just want to print out a list of numbers and skip a couple of them based off of a couple different conditions. Well, we could say that we only want to be able to print out even numbers. How would we do that? Well, we could say if and we could go bullion and convert I and the remainder operator from two. What this is going to do is give me back a value off zero whenever it's an even number, which means it's gonna be false. So in that situation, that's why the Bull Ian's here converting the zero interval false. And it's playing, if false, that's what that means. Well, then we're going to say continue. What continue means is we want to skip all the code that comes after this and jump back up here, increment the value of I and then continue executing through the code that's going to effectively allow us to skip odd numbers and not show them now in a situation which is this false, that means it's going to continue down here. Well, you say now is if the value is equal to 10 which jumped completely out of the four loop. And let's do whatever comes after this curly bracket down here. How we do that. As we would say, If I is equal to 10 well, then break and that's going to jump us out of the 4 11 so continues going to jump us back up to the beginning of four looping continue execution Break is going to jump us after this curly bracket, and that is the only way that they really differ. And otherwise it's going to print out the data on our screen and you could see that it printed out 246 and eight. And it didn't pronounce 10 because of this guy right here. Now there is a whole bunch of different types of for loops inside of Swift. I also use what's called the four in Loop so we could say four j in. And then we could use a range so we could say the range of values that Jay's gonna have or negative five the whole way through five. And it's gonna increment Those buy one each time and we could come in here and print that out and you could see it printed out Negative five negative for the whole way through 25 could also come in here. Let's throw in a quote and then let's cycle through this quote and see if we can match the total number of A's in the quote. You could save our gnome of A's like this and started off with zero and then cycled through . Single character is gonna be the temporary holding cell each time it cycles through all of the letters in quote, and each time it goes through there, it's going to say, Hey is the single character that you pulled out of this string equal to a, and this is going to match only lower case A's not uppercase A's. And in this situation in which we don't forget to put your curly bracket inside of their very important and also don't forget to close off your curly bracket. So in situations which we have a match for, a neighs will say number of A's and and shorthand notation. And then, after the four loop, we could put in our results. You could see weaken, cycle through ranges, weaken cycle through a raise, weaken cycle through a whole bunch of different things. So it's well cycle through a race here in a second. So number off A is of a is you see the total number of A's. And that quote comes out at six. Now that it was talking about cycling through a raise, let's come in here and cycle through one. So it's create an array called people, and this is an array string. She has a tutorial, continues. I keep coming back to all the things that I was skipping previously. There we go created are right when a cycle through it will go four individual person in people, right? And here we'll just keep it nice and simple and print that on a screen and you see Bob Bread and Paul bounced inside of there. We can also cycle through dictionaries. Let's go on, Let's do that. Let's create a dictionary called Heroes is equal to and we'll have Superman, which is going to be the key. And then Clark Kent is going to be the value. We're going to separate these with commas. There we go created a bunch of dictionary values. We can now cycle through them with the for loop will have public name and then secret identity in Heroes. We could get the keys and the values, and we're just going to say heroes is the dictionary that we want a cycle throw, and then if we want to print them out on the screen, of course, we just use public name is and our secret identity after that. You see, I made a little bit of an error. Need to come in here and get rid that comma. Put a colon in there instead, and you could see it cycled through the dictionary and printed out. Batman is Bruce Wayne flashes Barry on and Superman is Clark Kent. There's a whole bunch of different ways we can use four loops going to introduce a couple. Maura's a tutorial comes on, let's jump in the wild loops while loops Very similar, of course, two or four loop except we're going to create are initialized value that we're gonna increment outside of the while loop. They were going to say that we want to continue cycling through things as long as K is less than or equal to 10. And we can just come in here and print the value of K in that situation, and then you just need to increment inside of your while loop, and that's gonna cycle thrown print one through 10 or zero through 10 and then we also have the do while loop again. The value are going to be in commending you wanna put outside of it, and the only difference is going to do while loop, and the while loop is the do while loop is going to do everything that is inside of here at least one time, whether the condition is true or not, there we go. We can instrument the value of L in that situation. And the reason why is it goes through that whole entire list of code and then it checks if l is less than or equal to 10 at the very end of it. And you could see that it printed that out right there. And you can also see that No, there is no set Michael in there, but you could put it in there. So either way just depends on if you want to use semicolons or not. And that brings us to functions. Now functions are gonna allow us to reuse code as well as better organized or code. So let's create a couple simple functions. Let's create one that just, ah, say hello And what we can dio iss say that we're going to be receiving a string in this situation, which we're going to give the value of name. And that's the only attribute it's going to be receiving. And whenever it gets that name sent over to it, it's just gonna print out Hello name so little interaction. If we want to call, say hello tohave it, do something on the screen we just say, Say hello and you could see right here. If we don't pass the argument, it is going to give us an air. Whoever we put on a little name inside of there, it's going to jump back and spit out Derek there on the screen. No, it's ratcheted up and make more and more complicated functions. Let's say we wanted to create a function is going to some two numbers. Let's call it gets, um again, we're going to type in whatever we want the name for the attributes that's being sent in. We're going to give it a data type. If we wanted to give it a default value, we could also do that by just typing in equals to one. So it's gonna have a value of one If nothing's passed in and and then we'll also give this a default value. If we want to return a value, we're gonna put a little dash like that, making it look like an arrow. And then we're gonna take in the data type that we're going to be returning from other functions. That's a little bit odd, and then to return a value would just go numb one plus number two. Then we could pass in two values inside of here as the attributes. But if you do that without saying what variables they should be assigned to, you're gonna get in a little bit of an air here and in that situation to correct that, you would say someone, colon and to Colon. If you do that, it's gonna add those up. World's gonna be able to use something called very attic parameters, which is what we're going to use whenever you don't know how many attributes could possibly be sent into a function so well say function. Get some to create a new one and we'll say that we want to call this. It's actually gonna be an array of integers. We're gonna put dashes inside of there because we don't know how many were going to get. And then we're going to pass back an integer after the some has been calculated. Know what we can do is gov fireable some created imager started off with a value of zero and then cycle through this injure array. So numbs is the name of the injure, right? And then some like this, you shorthand notation. And then after it's done with all that, we can say return some and then we could just come down here and go some and in passing as many things you want. So we'll go get some to It doesn't matter. It's made you want, and it's automatically going to calculate the results of that. It's also a very useful thing. Now let's go over how we can affect values even outside of a function. So we're gonna do that. We're gonna create some strings here to make it simple. Say something like Happy and String Two is equal to sad Now, normally, whenever you pass a value inside of a function and you change it, you're actually passion in the value or not passing a reference to the actual variable. So any changes you make inside of that function or not gonna have an effect on it, however, you can change that quite easily. So let's say we want to have these be uppercase, so make upper case like this, and then we're gonna go in out, and that's going to allow us to change the value both inside of the function and then have it affect the value outside the function is going to get a string value in out again string to their that IHS curly brackets, and then we can get a string. One is equal to string one. And if you want to actually make a string upper case, that's what you dio and then we string to same thing with that. Then we'll be able to go make uppercase exactly like this. You could see it automatically put that and symbol in there, which means it's passing a reference and not a value. It will just go string one and string to. You can actually see that it worked right here inside of this little playground area. There's no reason to print that out. We're also going to be able to come in here and actually return multiple types from a function. And this is the two bull thing that I was talking about before. We'll go get multiple and will go number. It's an end, and it's going to be returning X two, which is an integer also as well as X three, which is also going to be an integer so you can return. Multiple values is very useful, so we'll go variable x two. And what say whatever is passed inside of this, we're going to just multiply that times two and then we'll do the same thing for the X