** ^{}**Introduction to BASIC

IF～END IF

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

IF statements

In case that there is only one statement that shall be excecuted when the condition holds, we can write that statement succeeding THEN and omit END IF.

Note that the presence of END IF depends on that THEN have a statement on the righthand side.

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 PRINT (-b-SQR(D))/(2*a),(-b+SQR(D))/(2*a) 40 END