Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
IF...THEN Statement Programming Example
◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
'These examples use single-line and block IF...THEN...ELSE
'statements to determine how many digits are in a number.
'Here is the single-line form:
CLS 'Clear screen.
DO
INPUT "Enter a number greater than 0 and less than 10,000:", X
IF X >= 0 AND X < 10000 THEN EXIT DO ELSE PRINT X; "out of range"
LOOP
IF X<10 THEN Y=1 ELSE IF X<100 THEN Y=2 ELSE IF X<1000 THEN Y=3 ELSE Y=4
PRINT "The number has"; Y; "digits"
'Here is the block form, which is easier to read and more powerful:
CLS 'Clear screen.
DO
INPUT "Enter a number greater than 0 and less than 100,000:", X
IF X >= 0 AND X < 100000 THEN
EXIT DO
ELSE
PRINT X; "out of range"
END IF
LOOP
IF X < 10 THEN
Y = 1
ELSEIF X < 100 THEN
Y = 2
ELSEIF X < 1000 THEN
Y = 3
ELSEIF X < 10000 THEN
Y = 4
ELSE
Y = 5
END IF
PRINT "The number has"; Y; "digits"