 In this lesson, we're going to look at flow control. Now think about Julia as a language in which you write lines of code and every line gets executed one after the other. You might want to write a piece of code though that you don't want every line to be executed. You want some lines to be skipped or you want some lines to be executed only under certain conditions. Now think about a little raft going down a river. The river forks and the raft can go down one of the forks and you can force it to go down one or the other. This is a very special kind of river because we can also have tiny little loops where the little rafters goes round and round. Now this is all called flow control. We can control the flow of execution and let's have a look what we're going to see in this lesson. We're going to talk about the easiest one perhaps, just branching our code through ternary operators, executing something or not executing something or at least executing something else by a ternary operator Boolean switches. We're going to have a look at the very useful if else if else end conditions, the four end loops. We're going to have a look at compound expressions and then while end loops. Let's start off with by looking at the ternary expressions. Now we're going to use what is called the term ternary operator. And you can see there it is a question mark. Now in this for this lesson you'll see the code's already been written out. It's just that in some places we're going to get to multiple lines of code and I don't want to have to type all of those and waste some of your valuable time that way. So we're going to have the code here which you can work along with. So first of all I'm going to create this variable called a computer variable. It's going to call be called a it's this little space in memory and inside of it I'm going to put a value which is 10 at this moment, which is an integer. So if I run that line of code what Julia will do in the notebook, it's going to print to the screen this output 10. Now here comes the ternary operator and it works like this. First of all, there's my ternary operator. You see the question mark and there's the colon. So what does it do? To the left of the ternary operator is the question that we ask. Is a larger than 10? Now remember a is just a computer variable. It holds a value and at the moment that value is 10. So the question there is really is 10 larger than 10? Now after the ternary operator is the two branches that the program can now take. So the first one is if this question is true and then the colon and what comes after the colon is what to do if the ternary operator returns a false. So you can well imagine that this is false, 10 is not more than 10. It's actually equal to 10 so it's not going to execute this first lot. It's going to execute the second lot. At the moment by this lot, I mean it's just a string of text. I can put anything in here, some more code to be executed, etc. I'm just using a string here as an example. So let's run this line, this cell of code and indeed it's no, it's not. That's what's executed and it's just because it's a string. If I put other words in there, those words would have been printed. It's just that the second lot or the lot after the colon gets executed if this is false. So if I change this to a is larger than or equal to 10, well 10 is equal to 10. So it's the first lot here, the yes it is string that is going to be executed and indeed it is. Yes, this is a different way of doing it. I can write everything in one line, r equals one and s equals two. So two computer variables, one called r, one called s, and each of them is going to contain an integer value with r having the value one and s the value two. I've put the semicolon there just to write everything on one line and the semicolon there is going to suppress the output to the screen. Look what happens. If I run that, we just see a change to four. There was no, the code was not written to screen. So here we have this print line statement, print ln. It's not particularly useful perhaps in the notebook, more useful in the REPL, in the terminal window if you run Julia there. But again, whatever is in these little brackets and the parentheses are going to be executed, it was going to be printed at least. And it is a ternary operator that is going to be executed here. It asks, is r less than s? Of course it is, so it's going to print this first thing to the screen. If not, it's going to print the second one and indeed one is less than two. So we know it is less, that is going to be executed and there we go. Just look at the difference though, because it's print line, it's printing it without the quotation marks whereas here it did print as quotation marks. Again, as I say, not a huge difference here in the notebook. Is r greater than s? And of course no, it's not going to be if I run that line of code. Just to show you here basically the print line output that gets rid of those quotation marks when it does print to the screen. Next up, we're going to look at Boolean switches.