ex.hlp (Topic list)
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...END IF Statement Example
                        Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
' The examples below illustrate use of the single-line and block form of
' IF...END IF statements to determine how many digits are in a number.
 
' To try this example:
' 1. Choose New Project from the File menu
' 2. Copy the code example below to the code window
' 3. Press F5 to run the example
 
' Single-line form.
 CLS                                   ' Clear the 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"
 PRINT "Press any key to continue..."
 DO
 LOOP WHILE INKEY$ = ""
 
' Block form.
 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"