IF - source-solutions/HELP GitHub Wiki

IF


IF truth_value {THEN|GOTO} [compound_statement_true|line_number_true [anything]][ELSE [compound_statement_false|line_number_false [anything]]]

If truth_value is non-zero, executes compound_statement_true or jumps to line_number_true. If it is zero, executes compound_statement_false or jumps to line_number_false.

Parameters

  • truth_value is a numeric expression.
  • line_number_false and line_number_true are existing line numbers.
  • compound_statement_false and compound_statement_true are compound statements, consisting of at least one statement, optionally followed by further statements separated by colons (:). The compound statements may contain nested IF to THEN to ELSE statements.

Notes

  • The comma is optional and ignored.
  • ELSE clauses are optional; they are bound to the innermost free IF statement if nested. Additional ELSE clauses that have no matching IF are ignored.
  • All clauses must be on the same program line.
  • THEN and GOTO are interchangeable; which one is chosen is independent of whether a statement or a line number is given. GOTO PRINT 1` is fine.
  • As in GOTO, anything after the line number is ignored.

Errors

  • If truth_value has a string value: Type mismatch.
  • truth_value equals 0 and line_number_false is a non-existing line number, or truth_value is nonzero and line_number_true is a non-existing line number: Undefined line number.
⚠️ **GitHub.com Fallback** ⚠️