1
00:00:00,780 --> 00:00:03,760
Welcome to this lecture about for loops.

2
00:00:03,930 --> 00:00:05,170
Before starting.

3
00:00:05,250 --> 00:00:14,580
We need to explain what is a loop a loop is a block of code that iterate a list of commands as long

4
00:00:14,670 --> 00:00:23,100
as the loop control condition is true so how it looks like here is the standard for loop.

5
00:00:23,280 --> 00:00:30,610
It takes first item from the list and assign its value to variable arc.

6
00:00:31,960 --> 00:00:39,470
Then a list of commands between the keyboard to do and done are executed and after this one loop is

7
00:00:39,470 --> 00:00:39,980
finished.

8
00:00:41,020 --> 00:00:49,170
Into variable Eric is assigned next item from the list and so on to understand it fully.

9
00:00:49,180 --> 00:00:51,410
We can look at this example.

10
00:00:51,480 --> 00:00:55,760
We are iterating through a list which contains three items.

11
00:00:55,870 --> 00:00:58,240
Mercury Venus and act.

12
00:00:58,420 --> 00:01:02,300
Firstly to variable planet is assigned variable Mercury.

13
00:01:02,340 --> 00:01:08,340
Then we will perform commands between keyboards due and done which in our case means printing value

14
00:01:08,410 --> 00:01:16,390
of variable planet which is now Mercury then into variable planet is assigned to Venus and we will print

15
00:01:16,390 --> 00:01:17,080
it also.

16
00:01:17,230 --> 00:01:24,040
And then finally available act is assigned into variable planet and Venus printed.

17
00:01:24,070 --> 00:01:31,150
There are no other items to loop over so the loop control condition is false and we are continuing with

18
00:01:31,150 --> 00:01:33,440
the script code after a keyboard.

19
00:01:33,460 --> 00:01:39,410
Done very often you can see looping over a value of a variable.

20
00:01:39,500 --> 00:01:43,780
Here you can see we have assigned into two variable plummets string.

21
00:01:43,850 --> 00:01:49,370
Mercury Venus at what will be the result if we loop over it.

22
00:01:49,370 --> 00:01:52,450
Result will be the same as in previous slide.

23
00:01:52,490 --> 00:02:00,710
So the question is why why the for loop prints each planet instead of printing just one thing.

24
00:02:00,710 --> 00:02:09,680
Because internal field separator definitely separate by space for loop doesn't see only one string thanks

25
00:02:09,680 --> 00:02:13,460
to internal field separator it sees space strings.

26
00:02:13,460 --> 00:02:23,510
Mercury Venus and act but if we in our example used quotation marks with the variable planets we would

27
00:02:23,510 --> 00:02:30,590
basically tell strictly follow created string planet and don't separate for that case.

28
00:02:30,590 --> 00:02:38,810
The for loop would iterate only one time and we would see printed Mercury Venus act as a one string

29
00:02:39,140 --> 00:02:47,260
on one line Well let's see another example with internal field separator into variable planets.

30
00:02:47,260 --> 00:02:53,110
We are assigning Mercury Venus ahead separated by comma for a loop.

31
00:02:53,110 --> 00:03:00,700
In that case would iterate only one time and we would see printed only one string as internal field

32
00:03:00,700 --> 00:03:03,770
separator doesn't contain comma symbol.

33
00:03:03,790 --> 00:03:11,480
There is nothing to separate in our variable s internal field separator default separates.

34
00:03:11,550 --> 00:03:19,830
Also by New Line we can assign into variable planets Mercury Venus and separated by New Line.

35
00:03:19,830 --> 00:03:28,650
And in that case would internal field separator separate it our string to three strings and as output

36
00:03:28,740 --> 00:03:34,890
of four loops we would see printed each planet on different line.

37
00:03:34,890 --> 00:03:38,830
We can in four loops also use wildcards.

38
00:03:39,030 --> 00:03:48,420
Here for example in the list are all text files and for each text file we are printing them using photo

39
00:03:48,420 --> 00:03:48,880
loops.

40
00:03:48,900 --> 00:03:52,180
We can integrate any number of times here.

41
00:03:52,220 --> 00:03:57,110
For example we are iterating through a list of 1 to 10 range.

42
00:03:57,120 --> 00:04:07,010
So 10 times iterating For loops are also hugely used for looping through all arguments provided as we

43
00:04:07,010 --> 00:04:10,080
can see in this example.

44
00:04:10,190 --> 00:04:14,420
We have also possibility to use for loops in C style.

45
00:04:14,420 --> 00:04:17,910
Here we are using double parenthesis and inside them.

46
00:04:18,020 --> 00:04:25,280
We are setting default value so we are starting here with variable ie equals to 1.

47
00:04:25,310 --> 00:04:31,610
Then we have loop control condition so we will iterate through this for loop when the value of variable

48
00:04:31,700 --> 00:04:38,940
IE is less than or equal to 10 and the last part is incrementing.

49
00:04:38,940 --> 00:04:47,880
That means at the end of each iteration we are increasing value of variable ie by 1.

50
00:04:47,910 --> 00:04:51,960
Of course we can also decrement and not only by 1.

51
00:04:52,010 --> 00:04:58,650
It's up to us of what operation we will do here but most commonly in this type of for loops is spared

52
00:04:58,650 --> 00:05:02,390
from increment operation by 1.

53
00:05:02,910 --> 00:05:09,930
So dad was a lot of information in very short time kind of exhausting but don't worry.

54
00:05:09,940 --> 00:05:16,350
Best way to remember the usage would be to seed on some example in next lecture.
