BASIC10.WPS

BASIC LANGUAGE PROGRAMMING

USING DO WHILE AND DO UNTIL LOOPS

So far you have been exposed to the FOR/NEXT loop. FOR/NEXT loops loop a preset number of times. There are several other types of loops used in BASIC programming as well. These loop an indeterminate number of times. These are the DO WHILE and DO UNTIL loops. They both employ the same syntax and continue to loop until some specified condition is met.

Here are examples of each:

EXAMPLE #1 (PASSWORD GUESSING GAME)

LET SECRET$ = "JENNIFER"

DO WHILE X$ <> SECRET$

PRINT " PLEASE TRY TO GUESS THE PASSWORD"

PRINT " IT IS THE FIRST NAME OF SOMEONE IN THE CLASS"

PRINT " PLEASE TYPE IN YOUR GUESS AND PRESS ENTER"

INPUT X$

LOOP

PRINT " CONGRATULATIONS - YOU HAVE GUESSED THE PASSWORD"

END

 

EXAMPLE #2 (PROGRAM COUNTS UP TO 50 THEN ENDS)

LET X = 0

DO UNTIL X > 50

PRINT X;

LET X = X +1

LOOP

PRINT " "X HAS NOW PASSED 50 IN VALUE"

END

 

ASSIGNMENT:

1) Re-write the computer program you wrote in basic9.wps to

guess a number between 1 and 10 but this time using DO

UNTIL LOOPS. The program is to tell the individual if he/

she had guessed high or low and congratulate him or her

when the correct number is guessed.

 

 

 

2) Modify the password guessing program above to give the

user only 5 tries at guessing the password. The program

will alert the user with each try, how many tries are

left. After 5 tries it will print "Sorry you failed to

guess the password correctly"

Copyright - Barry Boyle (bboyle@kawartha.net)