Programming Instructions - 500 Ways

Programming Instructions

I found these instructions in a manual about a computer programming language. Perhaps because of wording like this there are not more programmers than there are:

Look at the first compare of the second group of compare statements. The expression “r != s” will evaluate as a “true” since “r” was set to 0.0 above, so the result will be a non-zero value, probably 1. Even though the two variables that are compared are “float” variables, the result will be of type “integer.” There is no explicit variable to which it will be assigned so the result of the compare is an implied integer. Finally the resulting number, 1 in this case, is assigned to the integer variable “x”. If double equal signs were used, the phantom value, namely 1, would be compared to the value of “x”, but since the single equal sign is used, the value 1 is simply assigned to “x”, as though the statement were not in parentheses.

Finally, since the result of the assignment in the parentheses was non-zero, the entire expression is evaluated as “true”, and “z” is assigned the value of 1000. Thus we accomplished two things in this statement, we assigned “x” a new value, probably 1, and we assigned “z” the value of 1000. We covered a lot in this statement so you may wish to review it before going on. The important things to remember are the values that define “true” and “false”, and the fact that several things can be assigned in a conditional statement. The value assigned to “x” was probably a 1 but different compilers may assign a different value as long as it is non-zero.

Continuing on to the fourth example of the third group we find three assignment statements in the compare part of the “if” statement. If you understood the above discussion, you should have no difficulty understanding that the three variables are assigned their respective new values, and the result of all three are non-zero, leading to a resulting value of “TRUE.”

Some of your author’s code for a picture puzzle program written about ten years ago.

Leave a Reply

Your email address will not be published.