Okay. We're going to have our first example of a non-linear program. So far, the programs we've been writing and executing are do the first line, then do the second line, then there's a third line. Keep going until you do a return of zero and you end the program. Not all programs can be that simple. So it's very useful to have the ability to test something and then decide whether to do one of a number of things. Simple one would be one of two alternatives, and that's what we're going to study right now. Later we'll also study how to do things that are looping as well. But this is fundamental. We're going to either do Action 1 or Action 2 but not both. So this is our first program to use an if-statement. So looking at the program, we have what's an if-else-statement at the heart of what we're doing. The program is very simple. It asks the user for a speed. It's going to ask you to enter your speed as an integer. Then depending on what it sees as your speed, it executes that and says you have no speeding ticket or a speeding ticket. I think I've already compiled this. Let's just make sure. So it says enter your speed as an integer down at the bottom. Let's say my speed is 78. Sure enough, I get a speeding ticket. Now let me do that again. Says enter my speed as an integer. I say 62, and it says no speeding ticket. Okay. Let's go into more detail on the qualities you get in using how to properly use this kind of if-else expression. So the program, which I just called the file is C4E Week 3 P1 If. We can see how to use an if-else. The critical thing is the general syntax for it is if-expression in between parentheses. Then you do what I will call the true statement, else you'll do what I call the false statement. These expressions can be arbitrary, but they are frequently what we'll call relational. So the expression gets evaluated. If it sees a value of zero, it thinks false. If it sees a barrow that's non-zero, it thinks true. In the program we just wrote the relation was speed less than 65. For example, if you had entered for the speed 50, then that would be less than 65, and that was true which means that that expression evaluates to one. Which means that the print F is going to print new line, no speeding ticket. Similarly, if you had a speed, again this relation speed, less than 65 where you entered exactly 65 or more, then this would not be true. That means the expression would evaluate to zero. That means the false alternative would be taken. That means you would get your speeding ticket. Now, this could be altered. What if you made a mistake and you said no, no? Exactly at 65, you're not speeding. You see in California a lot of highways have a 65 maximum. So if you speed at less than or equal to 65, so this is a different relation. It includes 65 and then 65 remains true. The relational operators are four of them, less than, greater than, less than or equal, greater than or equal. You should be used to them from high school math. So also important to know their precedence. Their precedence comes out below arithmetic operators. So operators like plus, and times, and modulo, binds more strongly than the relational operators. So that after you saw a speed less than 65 plus i, the sub-expression 65 plus i would go first. That would be done. That addition would be done. It would be as if you had parenthesize this. You don't need to, but you have to understand what precedence is. It's probably a little clearer to do the parenthesizations. But that means this plus is done first. So you'd add an i, then you would do speed. So i might be some increment where the highway police gives you leeway. So maybe typically in your neighborhood that's four more miles. So that kind of increment might be more realistic about when you got a speeding ticket. All right. So it's a very elementary program. You should get out of it how to use an if-else. By the way, a simpler kind of statement is just an if, and the if-statement, you have if expression and then you execute the statement if it's true. So if you have an expression that evaluates to zero, then you omit the statement. Indeed you could have turned that if-else into two if-statements, but that would be not as elegant and also somewhat inefficient because you would be evaluating the relation speed less than 65 twice.