1
00:00:01,490 --> 00:00:07,070
Come back again in this lesson we're going to talk about the control flow in swift but she's essentially

2
00:00:07,070 --> 00:00:13,970
using conditional statements switches for loops of wire loops and something else that's called a repeat

3
00:00:14,030 --> 00:00:19,690
loop which is very similar to a do while in Objective-C and other programming languages.

4
00:00:19,880 --> 00:00:22,500
So let's go ahead and have a quick look.

5
00:00:22,700 --> 00:00:25,350
This is going to be one of our easier lessons.

6
00:00:25,380 --> 00:00:31,400
So I'm going to make it in let's make a playground for it because you know we can alternate between

7
00:00:31,400 --> 00:00:33,130
them a playground.

8
00:00:33,170 --> 00:00:38,750
And in my playground I'm going to say this is control flow.

9
00:00:39,620 --> 00:00:40,280
All right.

10
00:00:40,340 --> 00:00:47,780
So the first thing that you want to do is this I want to say where my ends is five and then I want to

11
00:00:47,780 --> 00:00:58,060
say if my index is four then do something else do something else.

12
00:00:58,160 --> 00:01:04,580
So the only thing that's different here is that you don't need to have practices around your condition.

13
00:01:04,610 --> 00:01:08,570
Even though you could which is something I'm really used to do it.

14
00:01:08,630 --> 00:01:12,990
I do the fact it would Qantas's around brackets around my condition.

15
00:01:13,220 --> 00:01:14,510
So that's one thing.

16
00:01:14,510 --> 00:01:17,940
The other thing is you must have curly brackets.

17
00:01:18,050 --> 00:01:24,320
So you know Objective-C and other programming language languages the immediate line after that if or

18
00:01:24,330 --> 00:01:27,870
the else doesn't have to have a carefully bracket around it.

19
00:01:28,010 --> 00:01:31,010
But in strafed you must have curly brackets.

20
00:01:31,400 --> 00:01:37,790
So that's about that whatever you used to do with IF statements before you can do it like this in here.

21
00:01:37,790 --> 00:01:40,690
The other thing is using a switch.

22
00:01:41,100 --> 00:01:48,530
So for a switch I'm going to say switch and I want to switch my ends and then like always are if it

23
00:01:48,530 --> 00:01:53,950
is one print purines are one.

24
00:01:54,170 --> 00:01:56,270
And if it is difficult to break.

25
00:01:56,840 --> 00:02:02,240
So you would only use break in cases where you don't want anything to happen.

26
00:02:02,240 --> 00:02:04,960
For instance I want to say chase two.

27
00:02:05,300 --> 00:02:07,360
I don't care about whatever is inside it.

28
00:02:07,370 --> 00:02:14,330
I use break otherwise you don't need to have a break in each case like what we had in Objective-C because

29
00:02:14,330 --> 00:02:15,910
you don't need to have the same columns.

30
00:02:15,910 --> 00:02:19,570
I'm just adding them because I'm used to that system.

31
00:02:19,570 --> 00:02:23,930
Then next thing you are talking about is a form which is a very simple thing.

32
00:02:24,230 --> 00:02:33,230
If you remember the objective c it was four in and I 0 0 is smarter than 10 plus plus so on and so forth

33
00:02:33,650 --> 00:02:43,430
in Strief that is written like these four are in the zero to 10 and that's about that.

34
00:02:43,430 --> 00:02:49,090
So if I say print now if I want to print the value of all right.

35
00:02:49,080 --> 00:02:57,410
In fact I could say that since to pollution that we talked about earlier on and knife fight execute

36
00:02:57,410 --> 00:02:57,910
this

37
00:03:02,930 --> 00:03:10,760
it will actually say up 11 times is running sprinting 0 to 10.

38
00:03:11,060 --> 00:03:19,460
If you don't want to include 10 if you mean a smaller or then you can say or or just a smaller you can

39
00:03:19,460 --> 00:03:25,420
say four in zero dot dot and then a smaller sign.

40
00:03:25,580 --> 00:03:32,870
So now this will happen only 10 times zero to 9 as you would expect in terms of the syntax.

41
00:03:32,870 --> 00:03:39,380
The only thing you really need to be aware of is that in a for loop you can not use round rackets so

42
00:03:39,380 --> 00:03:41,120
you cannot use phantasies.

43
00:03:41,180 --> 00:03:43,020
They have to be like this.

44
00:03:43,040 --> 00:03:47,610
If I put practice is I'm guessing it's going to give me some sort of error.

45
00:03:47,630 --> 00:03:48,190
Yes.

46
00:03:48,290 --> 00:03:50,770
So you cannot use around brackets.

47
00:03:50,780 --> 00:03:55,700
It has to be for the name of whatever you are doing so on and so forth.

48
00:03:55,880 --> 00:04:03,130
You could also do four in which is again very simple for any type get in.

49
00:04:03,290 --> 00:04:04,070
Hello.

50
00:04:05,960 --> 00:04:15,370
All trains any not like that of course trained any tactician that's about that.

51
00:04:15,540 --> 00:04:22,400
So this is essentially using for each object in my aere or whatever that we have been doing in the past.

52
00:04:22,560 --> 00:04:28,430
So use exactly identically except that now sprinting H E L L O.

53
00:04:28,560 --> 00:04:33,070
And in here again you don't need to have the round brackets.

54
00:04:33,070 --> 00:04:39,100
Now let's have a look at the do while and repeat vide which is essentially the do while.

55
00:04:39,120 --> 00:04:47,760
So if I have a value about my counter which is five I can say repeat.

56
00:04:48,270 --> 00:04:50,770
And this is the action I want to repeat.

57
00:04:50,820 --> 00:04:52,850
Let's say brains.

58
00:04:53,070 --> 00:04:54,370
What do I want to paint.

59
00:04:54,420 --> 00:04:57,010
Hello All right.

60
00:04:57,100 --> 00:05:00,170
Why what's the condition I want to use.

61
00:05:00,180 --> 00:05:02,180
Why is my counter.

62
00:05:02,400 --> 00:05:06,710
My counter is still larger than zero.

63
00:05:07,150 --> 00:05:14,470
And of course you have to change the condition so I can save my counter minus equal one.

64
00:05:14,580 --> 00:05:16,890
So it keeps subtracting from itself.

65
00:05:16,920 --> 00:05:21,070
If I run this is going to say hello hello hello hello hello.

66
00:05:21,090 --> 00:05:29,460
Underneath the stops and of course we have done this was obviously very simple to do while in Objective

67
00:05:29,460 --> 00:05:31,160
C or other languages.

68
00:05:31,260 --> 00:05:33,120
And of course we have the while loop.

69
00:05:33,240 --> 00:05:39,730
So I'm going to say counter to and that's going to be zero.

70
00:05:40,080 --> 00:05:42,040
And then I'm going to say why.

71
00:05:42,390 --> 00:05:42,910
What is it.

72
00:05:42,910 --> 00:05:48,280
Why it is voile counter to is still a smaller than 10.

73
00:05:48,720 --> 00:05:50,750
I wanna do this.

74
00:05:50,820 --> 00:05:52,190
What do I want to do.

75
00:05:52,230 --> 00:05:54,470
I want a prince.

76
00:05:54,600 --> 00:05:58,190
It's less or anything like that.

77
00:05:58,370 --> 00:06:04,910
And I want to say that the counter too keeps adding to itself plus equal 1.

78
00:06:05,250 --> 00:06:07,540
So let's run that.

79
00:06:07,550 --> 00:06:13,370
No it says it's less it's less is less it does it for 10 times from 0 to 9.

80
00:06:13,380 --> 00:06:16,260
As it says in here 10 times and that's about that.

81
00:06:16,500 --> 00:06:24,840
So once again if statements you don't have to have round brackets you must have curly brackets for the

82
00:06:24,840 --> 00:06:27,900
body of the if condition switches.

83
00:06:27,900 --> 00:06:34,990
You don't need to have Brekke unless you don't care about that case such as the default case for loops.

84
00:06:35,040 --> 00:06:41,670
You use them for whatever variable name you want in the range that you want.

85
00:06:41,940 --> 00:06:49,440
For the for in loops you use for anything that you want in whatever that you're trying to do.

86
00:06:49,830 --> 00:06:56,910
And then we have the loops which are exactly like what we had in Objective-C and we have repeat wind

87
00:06:57,150 --> 00:07:00,330
which is likely to do while in Objective-C.

88
00:07:00,630 --> 00:07:06,180
So there is one more thing I should mention even though it is not such a common thing but just so that

89
00:07:06,180 --> 00:07:14,520
you get a sense of it is what if you want it to have a for loop that goes through a set of numbers but

90
00:07:14,610 --> 00:07:16,560
it doesn't go one by one.

91
00:07:16,560 --> 00:07:19,130
What if your steps were to be different.

92
00:07:19,140 --> 00:07:27,960
What if in Objective C I wanted to say into Ivon 2 0 to 10 and I class equal of 5 or 4.

93
00:07:27,960 --> 00:07:30,550
I wanted to jump every four steps.

94
00:07:30,720 --> 00:07:33,440
So in interest we do that like this.

95
00:07:33,450 --> 00:07:42,420
Like I said it's not a very common thing but for all I gain astride on my stride has from two unbiased

96
00:07:42,840 --> 00:07:48,310
zero to 100 every 15 and then you do whatever you want.

97
00:07:48,310 --> 00:07:52,360
Doing so from a stride from 2 by.

98
00:07:52,560 --> 00:07:55,040
That's where you do things that you wanted.

99
00:07:55,260 --> 00:07:58,520
So let's keep it up to here and we'll move on to our next lesson.
