COMPARING VALUES

To compare values, we need operators. Boolean type plays an important role here.

Let’s use two previously defined integer variables containing integers 3 and 5

bool bResult = false

bResult  =  iFirstNumber < iSecondNumber

print bResult  

This code will output “true” because 3 is indeed less than 5, and  operator “<“ returned value true as a result of the comparison between these two variables.

Assigning a value of bResult = falseat the beginning of the code is called initialization of the variable and it is the recommended thing to do because the program could crash or misbehave if it attempts to use a variable that is not assigned any value.

Variable can be initialized during its declaration like this: 

bool bResult = false 

or in a separate line right after the initialization:

bool bResult

bResult = false

Next page ->
OPERATORS

Download “Become a Programmer in a Day” on Apple Books

Leave a comment

Your email address will not be published.