et us see conditional statements if is a conditional statement
here I should mention the condition if the condition is true then this block will be executed.
I will write C out Hello new line.
Now I must mention a conditional statement here he is giving an error message that expected expression.
So I will the write one let us see what happens.
I run the program.
Hello.
Is displayed here.
If I write as 0 .
It is false see here I got a warning that code will never be executed.
Silence by adding parentheses to mark code as explicitly dead.
But still I will run because this is the warning program will compile and run.
It's working and has displayed hello It means minus 10 is taken as true.
I can use this keyword true also.
Now let us.
add else block to this one
here.
I will display a message cout bye
endl let us run this and see
only hello is displayed and here I am getting a warning that this code is not reachable, never executed
because I have mentioned true here so always it will enter in.
If block it will not enter into else block and instead of true.
If I write false here then still I get a warning that this blog will not be executed at all.
This block will be executed any way I can run and see what happens.
It will go in the else block and display.
Bye.
Yeah it is displaying bye here so I can use constant values like 0 or 1 or any other number for true
or I can write keywords like true or false.
Let us write a program to take the roll number from the keyboard and check whether that number is valid
or not.
So for that I will declare a variable called Roll and cout
enter your roll number
cin roll
Here we check if rule number is less than 1 number cannot be zero.
Mostly all numbers start from 1 only if it is less than 1.
Then we will say say cout invalid roll number
else cout valid roll no.
So the common thing found mostly in like on any Web site.
If you are registering they us ask for email.
They will check whether your email is right or not.
they will ask age or date of birth.
But if you enter a future date then they will say it will give a message that your data is invalid
so that the called as validation.
So this is like a validation code.
So after taking a roll no. i am just checking weather the roll number is valid or not.
So roll no. cannot be less than 1 so that's what I am checking if it is less than onc say a valid otherwise
valid Let's run and see the program
enter your roll number minus one invalid number.
Here is a message invalid roll no.
two enter, valid roll no.
There's a valid number that's it.
So you can try this program on your computer.
I suggest you do try this program by yourself.