QBASIC if then else

In QBasic, you can use the IF...THEN...ELSE command to perform different actions based on a condition. Here is the basic syntax for the IF...THEN...ELSE command:

IF condition THEN
   statements
ELSE
   statements
END IF

The condition that we will provide is a logical expression that evaluates to either TRUE or FALSE. If the condition turns out to be TRUE, the statements following THEN will be executed. Otherwise, if the condition turns out to be FALSE, the statements following ELSE will be executed.

Here is an example of how to use the IF...THEN...ELSE command in QBasic:

INPUT "Enter a number:", num

IF num > 0 THEN
   PRINT "The number is positive."
ELSE
   PRINT "The number is found to be negative."
END IF

In this example, the user is prompted to enter a number, and the number is stored in the variable "num." The IF...THEN...ELSE command checks whether "num" is greater than 0. If it is, the program prints "The number is positive." If "num" is not greater than 0, the program prints "The number is negative or zero."

You can also use multiple ELSE statements to test for multiple conditions:

INPUT "Enter a number:", num

IF num > 0 THEN
   PRINT "The number is positive."
ELSE IF num < 0 THEN
   PRINT "The number is negative."
ELSE
   PRINT "The number is zero."
END IF

In this example, the program first checks whether "num" is greater than 0. If it is, the program prints "The number is positive." If "num" is not greater than 0, the program checks whether "num" is less than 0. If it is, the program prints "The number is negative." If "num" is not less than 0, the program prints "The number is zero."

These examples demonstrate how to use the IF...THEN...ELSE command in QBasic to perform different actions based on a condition.