The computer doesn't care what we name things (unless the name clashes with something else). The letter 'a' has no significance at all. If you used a shoe-box and labelled it 'old DVDs' the world wouldn't end if you decided to fill it with socks, even though you might be confused on the day you move out.Īlso note that, like any label, what we chose as a label for the variable was entirely arbitrary. A variable doesn't care what it contains. then the variable 'a' would contain the number 10 rather than "Can write a sentence". The '=' sign pushes the words "Can write a sentence" into the ingredient box labelled 'a'.Īfter this, 'a' contains the words "Can write sentence". We use variables to store data and then perform operations on that data to get outputs we want. It's like a label on an ingredient box that can contain anything at all. Let's take a look at how this plays out in actual code: This means 'put the word "thingy" into the shoe box in the cupboard with the label '5'. This means 'make an array called cupboard'. The format for creating an array is like this: We first have to say 'Hey! This data is going to be an array, and will contain more labels!' In addition, when we start putting in values, we need to say 'which shoebox in the cupboard we want to put the value in'. Apparently we have a problem with shoes.īecause we now want to name a collection as well as individual shoe boxes, putting data into the whole thing looks a bit different. We might have more in the garage, or under the bed. With an array, it's simply a collection of shoeboxes with a label of its own, like 'the shoe boxes in my cupboard'. With a simple variable we just say a = 5 to make a piece of data with the label 'a' contain the value 5: fill shoe box 'a' with 5. If I put a 2 small shoe boxes inside a large shoebox you'd be just fine. They look a little different from variables in how we create them, but that doesn't mean they are scary. In the case of arrays, they are shoeboxes that can contain yet more shoe-boxes. You've previously seen how you can get sections of code to run again and again using 'loops' like for i = 1, 5 do, but arrays are where this starts to show its usefulness.Īrrays are just like other variables: shoeboxes containing data. Arrays are where the fun with coding really begins.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |