header

If-Then Example

Consider a simple program that asks the user for an integer number and displays its absolute value. The program uses this variable:

The graphic below illustrates just the processing logic; the input of v and the output of the absolute value are not shown.

The variable, v, is used to store the integer value entered by the user. If the value of v is negative then the value is negated and the result is assigned to v (replacing the original value). If the value is not negative (the condition is false) then the if clause is skipped and the value of v is unchanged. In either case, execution proceeds to the next statement in the program.