View Poll Results: What do u feel about perversity on the net?
- Voters
- 9. You may not vote on this poll
-
October 16th, 2003, 10:09 PM
#1
An Attempted Qbasic Tutorial Part III
PART THREE: MORE ABOUT STRINGS, BOOLEAN STATEMENTS, IF LOOPS
So now you know enough to start making some (very) simple programs. If you didn’t understand from the last tut, a string can contain anything. This could be a string: jfigf954jhg85u%Vyt67%&^$$46ft5tygubsf…” You get my point. ANYTHING inside quotation marks is a string. Like PRINT “979-1299” makes the computer print 979-1299. But, if you just write PRINT 979-1299, the computer will print “-320” because the computer was told to subtract 1299 from 979. Quotation marks are majorly important.
The VAL command is one that I personally don’t use that often, but you should know anyway. It’s purpose is to convert strings in to numbers. For example VAL(“5”) will return a value of 5. For a string like VAL(“Hello”) or any string with letters returns a value of zero. IMHO, this is a kinda pointless command, being that you can just do something like variable = 5 in stead of variable = VAL(“5”) .
Also, why bother put ting a number in a string when you’re just going to take it back out again?
Ok, now on to Boolean expressions. They are part of Boolean algebra, which was named after (who’ve thought?) a man named George Boole. Boolean expressions are just expressions where the variable is true or false. In Qbasic, the best way to do this are the If commands.
If commands are used to tell the computer what to do under certain circumstances. A real life example of this is when you ask yourself “Do I want pizza or pasta for dinner?” If you wan pizza, you will order a pizza. If you want pasta, you’ll make some pasta. For every IF that you use there will be an END IF after that IF is done telling the computer what to do.
Here is an example, try to analyze what this code will do if executed:
CLS
IF (200>10) THEN
PRINT “This will print all the time.”
ELSE
PRINT “This will never, ever print”
END IF
END
BASICally, {rimshot..i bet your getting sick of my dumb jokes, aren’t ya?} this program checks if 200 is greater than 10. If it is, it will go to the third line of the code. If not, then it will go to the fifth line of code. Naturally, 10 will never be greater than 200, so it will always go to the third line.
Also, you can use variables in your boolean expressions. Take a look at this code:
CLS
INPUT “How many pets do you have?” ; pets
INPUT “How many kids do you have?” ; kids
IF (pets > kids) THEN
PRINT “You have your priorities in the right order!”
ELSE
PRINT “What ever possessed you to have more kids than pets?”
END IF
END
You should be able to under stand that one. Right? Or am I a failure as a tutorial writer? Didn’t think so. If you have more pets than kids, it goes to the fifth line of the code. Anything else, it will go to the seventh line of the code.
Another Boolean operator is AND operator. You use this to link two Boolean expressions. You can rewrite the above code and make it more picky when it judges. Like this:
CLS
INPUT “How many kids do you have” ; kids
INPUT “How many pets do you have” ; pets
IF (kids>pets) AND (kids >= 1) THEN
PRINT “What is wrong with you?”
IF (pets>kids) AND (pets>= 0) then
PRINT “You have your priorities in the right order!”
END IF
END IF
END
Well, I’m done for this one. Keep checkin for more :-p
\"Look, Doc, I spent last Tuesday watching fibers on my carpet. And the whole time I was watching my carpet, I was worrying that I, I might vomit. And the whole time, I was thinking, \"I\'m a grown man. I should know what goes on my head.\" And the more I thought about it... the more I realized that I should just blow my brains out and end it all. But then I thought, well, if I thought more about blowing my brains out... I start worrying about what that was going to do to my goddamn carpet. Okay, so, ah-he, that was a GOOD day, Doc. And, and I just want you to give me some pills and let me get on with my life. \" -Roy Waller
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|