QBASIC Program to print the pattern 54321, 5432, 543, 54, 5. This pattern can be print by using nexted for loop. In outer loop will be looped 5 times in ascending order (1 to 5) and inner loop will be loop from 5 to number of outer loop item in decending order. Then value of inner loop will be printed in the console one after another.
CLS
FOR i = 1 TO 5 STEP 1
FOR j = 5 TO i STEP -1
PRINT j;
NEXT j
PRINT
NEXT i
END
OUTPUT
5 4 3 2 1 5 4 3 2 5 4 3 5 4 5
Using SUB ... END SUB
DECLARE SUB Pattern()
CLS
CALL Pattern
END
SUB Pattern ()
FOR i = 1 TO 5 STEP 1
FOR j = 5 TO i STEP -1
PRINT j;
NEXT j
PRINT
NEXT i
END SUB
Using FUNCTION ... END
DECLARE FUNCTION Pattern()
CLS
r = Pattern
END
FUNCTION Pattern ()
FOR i = 1 TO 5 STEP 1
FOR j = 5 TO i STEP -1
PRINT j;
NEXT j
PRINT
NEXT i
END FUNCTION
4897