``

prev Menu next

Introduction to BASIC IF～END IF
IF～END IF
When the condition holds, the statements written between an IF line and an END-IF line shall be executed.
Example. The solutions of a quadratic equation.

    10 INPUT a,b,c
    20 LET D=b^2-4*a*c
    30 IF D>=0 THEN
    40    PRINT (-b-SQR(D))/(2*a),(-b+SQR(D))/(2*a)
    50 END IF
    60 END

IF～ELSE～END IF
When the condition holds, the statements written between an IF line and an ELSE line shall be executed and when the condition fails, the statements written between the ELSE line and the END-IF line shall be executed.
Example. A program which solves a quadratic equation.

    10 INPUT a,b,c
    20 LET D=b^2-4*a*c
    30 IF D>=0 THEN
    40    PRINT (-b-SQR(D))/(2*a),(-b+SQR(D))/(2*a)
    50 ELSE
    60    PRINT "No solutions"
    70 END IF
    80 END

[Note] inequality signs
The inequality signs ≤，≥，≠ are denoted by <=，>=，<> ,respectively.
IF ～ END IF