1 00:00:01,760 --> 00:00:07,820 In this lecture, I would like to talk about coding books, so why we need coding blocks, code books 2 00:00:07,820 --> 00:00:16,010 are used to group together lines of code that has the same purpose, like in case of which we use which 3 00:00:16,010 --> 00:00:20,990 to decide the color of the car and printed out a text based on that. 4 00:00:21,500 --> 00:00:30,320 So what coding books are by definition, they are zero or more statements enclosed embraces, but it 5 00:00:30,320 --> 00:00:31,790 can be a for loop. 6 00:00:31,790 --> 00:00:39,110 And if statement a class or something else with curly braces, we are going to see some letters for 7 00:00:39,110 --> 00:00:45,140 code blocks and see how variables can be accessed in and outside of a code. 8 00:00:45,200 --> 00:00:47,450 OK, all right, let's do this. 9 00:00:47,810 --> 00:00:55,310 A code block has a starting curly brace and an ending curly brace, and the code that belongs to it 10 00:00:55,460 --> 00:00:57,020 is between the braces. 11 00:00:58,130 --> 00:01:05,750 We can also have situations when we have a code lock in another one, we have a blue and a red here, 12 00:01:06,110 --> 00:01:12,470 the red code block, and before the blue one, let's see a concrete example for this. 13 00:01:13,190 --> 00:01:22,970 We can have a for loop with an if statement in it for loop block wraps the if statement and if block 14 00:01:23,180 --> 00:01:24,980 is part of the four block. 15 00:01:26,260 --> 00:01:32,820 Now, let's move on to variable access, the best way to explain this is by using an example. 16 00:01:33,760 --> 00:01:38,650 So we have two blocks here, an inner and outer. 17 00:01:39,400 --> 00:01:46,690 If you create a variable outside of the red block, you can still access it in the red block and you 18 00:01:46,690 --> 00:01:52,870 can even modify it by the end of this code, the number of the owners will be six. 19 00:01:54,300 --> 00:01:58,980 Now, let's take another example when you define a variable in the red. 20 00:01:59,640 --> 00:02:07,140 So now the number of the owner is variable in the red, but we would like to access it outside of the 21 00:02:07,140 --> 00:02:07,500 red. 22 00:02:08,130 --> 00:02:13,700 The problem is that after the red block is ended, that variable stopped existing. 23 00:02:14,400 --> 00:02:17,490 So we get an error if we would like to use that. 24 00:02:18,390 --> 00:02:25,290 We call these type of variables local variables, there are other types of variables like class variables 25 00:02:25,470 --> 00:02:27,570 that will be covered later in the course. 26 00:02:27,960 --> 00:02:29,620 That's all about code blocks. 27 00:02:29,640 --> 00:02:30,960 It was a shorter one. 28 00:02:31,720 --> 00:02:33,780 Now, let's move on to the coding part.