header

If-Then-Else Example

Consider a simple program that asks the user for an integer number and displays a message indicating whether the number is negative ("Yes") or not ("No"). The program uses these variables:

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

The variable, v, is used to store the integer value entered by the user and the variable msg is used to store the appropriate message. If the value of v is negative (less than zero) then the string "Yes" is assigned as the message value. Otherwise, "No" is assigned as the message value. In either case, execution proceeds to the statement that follows the if..then statement.