New to QBasic

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators: Administrator, Global Moderator

Post Reply
ZZUB
Newbie
Posts: 1
Joined: Mon Oct 02, 2006 6:14 pm

New to QBasic

Post by ZZUB »

Hi
Ive only recently started using QBasic at college and I would like to know how to loop something if a certain value is met... heres a silly example

DIM Username AS STRING
DIM Sentence AS STRING

CLS

INPUT "Please type your user name"; Username

INPUT "Please type sentence(s)"; Sentence

CLS

PRINT Sentence

IF Username = Mance THEN

PRINT "Invalid sentence structure, please input again"

ELSE

PRINT "Good job!"

END IF

How would I make the user 'Mance' have to start from the beginning?
Thanks...
buff1

Post by buff1 »

The easiest (though not the most popular) in this particular situation is with a goto

Code: Select all

DIM Username AS STRING 
DIM Sentence AS STRING 
START:
  CLS 

  LINE INPUT "Please type your user name"; Username 

  LINE INPUT "Please type sentence(s)"; Sentence 

  CLS 

  PRINT Sentence 

  IF Username = Mance THEN 
    PRINT "Invalid sentence structure, please input again" 
    GOTO START
  ELSE 
    PRINT "Good job!" 
  END IF 
(I also replace input with line input)
Bulldog
Newbie
Posts: 4
Joined: Fri Nov 03, 2006 6:34 am

Post by Bulldog »

DIM Username AS STRING
DIM Sentence AS STRING

DO

CLS

INPUT "Please type your user name"; Username

INPUT "Please type sentence(s)"; Sentence

CLS

PRINT Sentence

IF Username = Mance THEN

PRINT "Invalid sentence structure, please input again"

ELSE

PRINT "Good job!"
EXIT DO

END IF

LOOP
buff1
Jr. Member
Posts: 19
Joined: Mon Oct 30, 2006 4:37 pm
Contact:

Post by buff1 »

Note:
should be
If UserName = "Mance" then
better is:

If Ucase$(UserName) = "MANCE" then
Post Reply