Welcome.
Now, I'm going to show you an example program about Sharriff statements.
OK, let's get started.
All right, now in this program, I'm going to get a number from the come on line, then I'm going to
print it by doubling it.
For example, when I read it like this, go around mean that go Cotan, it will display 20.
All right.
That's great.
This program now.
First, I'm going to use a simple statement to set the oyster marks to a variable right inside the if
statement like this.
Then I need to type the condition expression, so I'm going to type a semicolon here.
The users should provide a number for the program, right?
So now I'm going to check the length of the past arguments to see whether the user has provided an argument
to the program or not.
OK, if it's not too, then I'll display a message like this and give me a number.
OK, let's try this now, let's call it in arguments first go around may not go, OK, as you can see,
the Prince terror message kill it works.
Now, let's create another branch here.
I'm going to convert the past number using the TOI function like this.
Here, I'm just short, declared Arabel in a simple statement, and I used a blank identifier to skip
the converted value.
For now, I'll change it soon, you'll see.
OK, now I'm going to check for an error like this.
So if the error is near that, it will mean that the conversion has failed.
So let's display an message first.
I'm going to type of formal text, cannot convert person to new line that I'm going to pass the command
line argument a one.
OK, now let's run this program using a name no value like this one.
This way I can check whether the program works or not.
As you can see, it cannot convert.
Wow.
Let me call it again without any arguments this time.
So it also checks for that cool.
Now, I'm going to change this blank identifier here to an variable.
So the eight hour function will save the converted number into this web, OK?
Do you know why I did it like so I mean, why I've typed a blank.
I didn't fire first, then I change it to the variable.
Since I didn't use the amber yet, so I wanted to run the program first, or it would give me valuable
unused air.
Now I'm going to use it.
That's why I've changed it to the Amable now.
OK, if the program reaches at this point, that means that everything is fine, there is a numeric
argument, so let's print it now.
I'm going to print it like this, I'm just going to type person test multiplied by two espersen the
Nula.
Then I'm going to pass the command line arguments, and that's the way I'm going to pass it, an expression
that actually multiplies the cumulative number like this and multiply it by two.
OK, let's run it now.
Hopes there is another right.
Let's check it out now.
Says that and and variables are not defined here.
It's because there are new variables inside the block, then only that block can use them.
This is what happens here.
This printer is out of the if statements block, so it can't access to the variables declared in the
if statement.
Now, let's move this printf inside and ask branch like this.
Now, it's OK, as Branch can see, and access all the declared variables inside this, if statement
is because the AZ branch belongs to this if statement.
So this acid branch also belongs to the same incident.
So that's why it can see the A1 variable here, you mean it was declared in previous if branch.
Let me explain this to you by quickly adding comments on top of them so this if Branch can only see
the Arab.
And this as a branch can see the available and also an Arab abels and this as Branch can see all of
the variables declared inside the whole if statement.
So each branch can see only the variables of their own and from the previous branches.
This is how scoping works in a statement with multiple blogs like this.
So please bookmark this moment, you will get across to this in the upcoming lectures as well.
Not that this time I haven't used in return statements to quit from the program, right.
Since it only excuse the branches depending on the conditions, so I don't need to quit by typing a
return or something else, for example, here, I don't need to type return.
It's because there is nothing outside of this if statement.
It is the last statement in the program, so it handles all the necessary conditions already.
All right.
Let's try this program now.
I'm going to call it without any arguments like this.
OK, it displays give me a number, cool.
Now let's be a bad boy and let's give it a name number for now like this.
As you can see, it says that I cannot convert that one.
It's OK.
It works.
Now, let's be a good guy and give it a proper number like this for the two, all right.
It works.
It has multiply 42 by two and it has turned eighty four and is correct.
Now, I'll help you understand how simple statements and blocks in a statement with multiple blocks
works.
So in summary, declared names in a block are only available to that block.
However, they are also available to the following clauses or branches if they are declared using a
simple statement.
All right, congrats now you know how the short statement works in the next lecture, I'm going to show
you one more example program.
See you there.