Come back again in this lesson we're going to talk about the control flow in swift but she's essentially
using conditional statements switches for loops of wire loops and something else that's called a repeat
loop which is very similar to a do while in Objective-C and other programming languages.
So let's go ahead and have a quick look.
This is going to be one of our easier lessons.
So I'm going to make it in let's make a playground for it because you know we can alternate between
them a playground.
And in my playground I'm going to say this is control flow.
All right.
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
say if my index is four then do something else do something else.
So the only thing that's different here is that you don't need to have practices around your condition.
Even though you could which is something I'm really used to do it.
I do the fact it would Qantas's around brackets around my condition.
So that's one thing.
The other thing is you must have curly brackets.
So you know Objective-C and other programming language languages the immediate line after that if or
the else doesn't have to have a carefully bracket around it.
But in strafed you must have curly brackets.
So that's about that whatever you used to do with IF statements before you can do it like this in here.
The other thing is using a switch.
So for a switch I'm going to say switch and I want to switch my ends and then like always are if it
is one print purines are one.
And if it is difficult to break.
So you would only use break in cases where you don't want anything to happen.
For instance I want to say chase two.
I don't care about whatever is inside it.
I use break otherwise you don't need to have a break in each case like what we had in Objective-C because
you don't need to have the same columns.
I'm just adding them because I'm used to that system.
Then next thing you are talking about is a form which is a very simple thing.
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
in Strief that is written like these four are in the zero to 10 and that's about that.
So if I say print now if I want to print the value of all right.
In fact I could say that since to pollution that we talked about earlier on and knife fight execute
this
it will actually say up 11 times is running sprinting 0 to 10.
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
say four in zero dot dot and then a smaller sign.
So now this will happen only 10 times zero to 9 as you would expect in terms of the syntax.
The only thing you really need to be aware of is that in a for loop you can not use round rackets so
you cannot use phantasies.
They have to be like this.
If I put practice is I'm guessing it's going to give me some sort of error.
Yes.
So you cannot use around brackets.
It has to be for the name of whatever you are doing so on and so forth.
You could also do four in which is again very simple for any type get in.
Hello.
All trains any not like that of course trained any tactician that's about that.
So this is essentially using for each object in my aere or whatever that we have been doing in the past.
So use exactly identically except that now sprinting H E L L O.
And in here again you don't need to have the round brackets.
Now let's have a look at the do while and repeat vide which is essentially the do while.
So if I have a value about my counter which is five I can say repeat.
And this is the action I want to repeat.
Let's say brains.
What do I want to paint.
Hello All right.
Why what's the condition I want to use.
Why is my counter.
My counter is still larger than zero.
And of course you have to change the condition so I can save my counter minus equal one.
So it keeps subtracting from itself.
If I run this is going to say hello hello hello hello hello.
Underneath the stops and of course we have done this was obviously very simple to do while in Objective
C or other languages.
And of course we have the while loop.
So I'm going to say counter to and that's going to be zero.
And then I'm going to say why.
What is it.
Why it is voile counter to is still a smaller than 10.
I wanna do this.
What do I want to do.
I want a prince.
It's less or anything like that.
And I want to say that the counter too keeps adding to itself plus equal 1.
So let's run that.
No it says it's less it's less is less it does it for 10 times from 0 to 9.
As it says in here 10 times and that's about that.
So once again if statements you don't have to have round brackets you must have curly brackets for the
body of the if condition switches.
You don't need to have Brekke unless you don't care about that case such as the default case for loops.
You use them for whatever variable name you want in the range that you want.
For the for in loops you use for anything that you want in whatever that you're trying to do.
And then we have the loops which are exactly like what we had in Objective-C and we have repeat wind
which is likely to do while in Objective-C.
So there is one more thing I should mention even though it is not such a common thing but just so that
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
it doesn't go one by one.
What if your steps were to be different.
What if in Objective C I wanted to say into Ivon 2 0 to 10 and I class equal of 5 or 4.
I wanted to jump every four steps.
So in interest we do that like this.
Like I said it's not a very common thing but for all I gain astride on my stride has from two unbiased
zero to 100 every 15 and then you do whatever you want.
Doing so from a stride from 2 by.
That's where you do things that you wanted.
So let's keep it up to here and we'll move on to our next lesson.