#Mastery16

16 1017

This is the second time I do this Mastery16 in order to make  two points out of it!

I will explain you how to use an else conditional..

But first, why use an else conditional and how does it work. Well the else conditonal  is use with the if conditional which i already explained earlier. The else conditional is when the if conditional is false, lets say, if you ask the user something with if and is true  it wil return you whatever you put there, but if it isn´t true then it will not print anyting unless you have another if or somekind of cout outside the if, but is more bother to do that. 

What the else conditonal does is  to return you something if the if conditional isn´t true.

The syntax for using else is:

“else

{

}”

As you can se is pretty easy to do so sure it will be no problem using it.

But let see how will you use with an if when the variable num is somehting the user give us and we ask for a number between 1 and 10:

“if (num 10)

{

     cout

} else {

       cout

}”

What does it say with words “If you put a number less than 1 or higher than 10 then it prints “Your number is invalid”, or if your numbers is higher or equal to 1 and less or equal to 10 then it prints “Great your number is between 1 and 10”.

So here you can se how easy is to use the else conditional and that it is very very useful when your are doing enourmous codes and your tired of writing or just because is not compplicated.

Hope you learn from this!

CC BY 4.0 #Mastery16 by Juan Carlos is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.