ZX BASIC:IF

From BorielWiki

Jump to: navigation, search

Contents

[edit] IF

IF is a very powerful control flow sentence that allows you to make decisions under specified contitions.

[edit] Syntax

IF expression THEN sentences
[ELSE sentences]
END IF

[edit] Example

IF a < 5 THEN PRINT "A is less than five"
ELSE PRINT "A is greater than five"
END IF

Sentences might be in multiple lines:

If a < 5 Then
    Print "A is less than five"
    a = a + 5 
Else
    Print "A is greater than five"
End If

Since IF is a sentence, it can be nested; however, remember that every IF must be closed with END IF:

If a < 5 Then
    Print "A is less than five"
    If a > 2 Then
        Print "A is less than five but greater than 2"
    End If
Else If a < 7 Then
        Print "A is greater or equal to five, but lower than 7"
    Else
        Print "A is greater than five"
    End If
End If

[edit] Remarks

  • This sentence is extended and not compatible with the Sinclair BASIC version: Every IF must be closed with END IF

[edit] See Also

Personal tools