{{QBDLDATE:07-31-2022}} {{QBDLTIME:23:42:07}} [[IF...THEN]] statements make boolean (true or false) evaluations to automate program decision making. {{PageSyntax}} ===Single-line=== : [[IF]] {{Parameter|conditionStatement}} [[THEN]] ''{code}'' [[ELSE]] ''{alternativeCode}'' : [[IF]] {{Parameter|conditionStatement}} [[GOTO]] ''lineLabel'' ===Block=== : [[IF]] {{Parameter|conditionStatement}} [[THEN]] :: ''{code}'' :: ⋮ : [[ELSEIF]] {{Parameter|conditionStatement2}} [[THEN]] :: ''{code}'' :: ⋮ : [[ELSE]] :: ''{code}'' :: ⋮ : [[END IF]] {{PageDescription}} * The {{Parameter|conditionStatement}} evaluation by [[IF]] must be true (-1) or a '''non-zero numerical value''' for the [[THEN]] ''{code}'' to be executed. * Multiple conditional evaluations can be made using inclusive [[AND (boolean)|AND]] or alternative [[OR (boolean)|OR]] conditional expressions. * [[THEN]] is not required when [[GOTO]] is used to send program flow to a line number or label. * [[IF]] statements can also have alternative evaluations using [[ELSEIF]] and [[ELSE]] conditions. * When the [[IF]] statement and/or code to be run is more than code line, an [[END IF]] statement must be used. * With multiple code lines to run, end the IF statement with THEN and place all of the code on lines below that line. * Multiple code line block statements require that the [[IF...THEN]], [[ELSEIF]], [[ELSE]] and [[END IF]] be on separate lines. * '''The IDE may return an error of ''[[NEXT]] without [[FOR]]'' or ''[[LOOP]] without [[DO...LOOP|DO]]'' when [[END IF]] does not end a statement block.''' * The '''QB64''' IDE will indicate an error in the IF statement line until END IF closes the statement block. * Use [[colon]]s to execute multiple statements in a single-line IF statement. * An '''[[underscore]]''' can be used anywhere after the code on a single-line to continue it to the next line in '''QB64'''. * '''NOTE:''' [[STRING]] values can only be evaluated in an IF statement if a value is compared to a literal or [[CHR$]] string value. '''QB64 may not compile literal IF string statements or indicate an IDE coding error.''' Use [[LEN]] or [[ASC]] to compare strings numerically. {{RelationalTable}}