Jump to content
xisto Community
Sign in to follow this  
AskAndrewD

Programming Using Basic Language! This topic will be big - PM me for more

Recommended Posts

--Please tell me if I have errors in this! Thank you!--

 

Welcome to Ask Andrew D's Guide to programming in the basic language. I am very experienced with basic and I have used several different types. I will provide you with each one. I'll assume you have played around with some type of language for just a short while, but gave up. Well, here are some parts that will help you in what you want to do!

 

REM // /* */: Rem is the easiest command you will EVER HAVE TO LEARN, guaranteed. It stands for a remark, or comment. Here is how you use it:

#1 \/// This is the more professional way of having comments./* This is also the same thingEXCEPT!You can have multiple lines inbetween.This is the how you end the comment:*/#2 \/Rem This is my game... do you like it? You can spam here and it won't affect your code! Also, this way only has a one liner - no multiple line comments!
Based on what they said, I don't need to explain. THERE IS ONE IMPORTANT NOTE THAT YOU MUST KNOW! Whenever you do code, ALWAYS use comments! Tell what you are doing, how you're doing it, what variables are what. Trust me, I'm a very experienced user - YOU MUST do this or your programming will be awful! You want to learn how to program good, right? Then use comments! LOTS! (Since this kinda goes in the same category, notice how the indentions in code later on have two spaces. I recommend you do this, because it makes your code a lot neater, and helps you understand what's going on.) If you don't use indentions and comments, you might as well make a program that suicides!

-----

 

VARIABLES (AND PRINT TOO!): Variables hold information - they store it. For example, if you want to keep a score throughout the game, then you would use a variable. Just like in an algebraic equation, a variable is (usually) a letter that you can refer to to call back information. Take this for a good example:

score=0
This code says that the score is equal to 0.

Now, lets say that we want the name of the player. Maybe his name is "Bob". (Our variable will be name="Bob")

print "Your name is "+name+"."
Now, don't get all angry. There are a few things you can learn that are the easiest parts of the basic language. First, notice the command "print". Print does not mean what it says. What print does is it puts text on the screen - in this case, it will "print" this:

Your name is Bob.

Next, notice how "Your name is is " and "." are in quotes. This means that it is text right on the spot, and not a variable. For example, if all you wanted to say was "Hello." then you would type this:

print "Hello."
which would display:

Hello.

I hope you get the idea of this print command now. Okay, moving on to the "+name+" part. Notice how it ISN'T in quotes, verifying that it is indeed a variable. Now here's where different programming languages come into different coding types. The one I am talking about uses + to add strings together. A string is any text that is made of characters that aren't numbers. For example, "I am a dufus! ?{}['^w" is a string, and "Hello5" is not because it has a 5 in there which is a number. Okay, so the one I'm talking about uses + to add strings together. What I mean by this is when it says,

"Your name is "+name+"."
"Your name is "

name

"."

 

These are all strings. Do you get the concept of strings now? Good. So, when it displays +name+ that means, "Add the variable name to what is being shown on the screen." So, when you make your program, your executable (That's where .exe comes from), it will run through it like this:

print "Your name is "+name+"."

Oh, okay! I need to put this on the screen.

First, I will put "Your name is "

Done!

Now, I will put the variable name on the screen right after it.

Now what was name again?

Uhh... it was "Bob"

Okay, now I'll put "Bob" on the screen.

Done!

Finally, I have to put "." on the screen.

Done!

Therefore giving you what you want.

ONE MORE NOTE ABOUT THIS! : If adding + to the print command does not work, look through the help for the command print. It may say to use something like ";" or ",". (Also, I think that some languages have it go to a new line if you put a special character in. E.g. print "Hi" and print "Hi"; are different. The one with ; will take the next print command to a new line.)

-----

 

IF THEN ELSE { } ENDIF- Okay, lets say that you want the computer to have a brain and not just display names on the screen. I will assume those of you that have a brain of your own will say, "OF COURSE! YES!" in your mind. If you haven't already guessed, "if" and "then" play out some logical thinking - very basic, but still logical. "If this happens, then do this." Okay, we will just focus on this part at first.

name="Jim"if name="jim" then print "Hey, your name is Jim!"
If you have any common sense at all, you will probably realize that this will come out:

Hey, your name is Jim!

Now that we (hopefully) get this simple concept down, let me go deeper into this. Lets say we want it to print out MULTIPLE words (or take multiple other actions such as moving the player in the game around or something - Don't get too excited, images probably won't be in THIS tutorial, if I do them at all!) There are two VERY common different ways to do this:

#1 \/if name="Jim"										  - Some languages you would use then after "Jim" {  print "Hey, your name is Jim!"  print "Jim is a nice name."}#2 \/if name="Jim"										  - Some languages you would use then after "Jim"   print "Hey, your name is Jim!"  print "Jim is a nice name."endif
I hope you get this concept. It is pretty simple. All you need to know is that the if/{} or if/endif commands START with if and END with }/endif. Also, the first way is usually in more professional programming languages, and is used the exact same way as in C or C++ (The most common non-basic programming languages known - and the best too!)

 

Okay, now to add else to the situation. Lets say you pick a name, either Bob or Jim. Then, we would assign name to it (This part will not be in the code). Here is how to use the else command:

#1 \/if name="Jim"							   (Then){  print "Jim is a good name."}else{  print "Bob is a good name, just like Jim."}#2 \/if name="Jim"							   (Then)  print "Jim is a good name."else  print "Bob is a good name, just like Jim."endif
I will assume that after all of this, you understand how to use if, then, else, {}/endif.

 

NOTE: You can have the { be directly after the if statement if you like, and some people do that. I myself find it easier and more readable if you have the { on a new line. Also, you can have infinity ifs inside each other. They computer-programmer-language-makers created it that way. If you really think about it, you will understand. (The first endif goes to the inside-most if, etc...). One last thing - endif may end if - Just like I said, different languages, different coding types.

-----

 

LOOPS: Loops are very simple to use yet for some hard to understand - especially the for-loop. That will be the last part of this tutorial. For these loops try to figure most of it out on your own. Only the important parts will I mention from now on.

do  print "Hi."loop
99% of you know what SPAM is, and this is how you SPAM "Hi." in your program! One way that "do" is used different has no "loop" in it. It goes like this:

i=5do{  print "Hi."  i=i+1}until i>=10
Now comes a new term, which I will describe in one minute. First, the do loop in this is different. It repeats forever UNTIL i is greater than or equal to 10. Now for the new term: i=i+1. That means WHATEVER THE HECK i is, add one to it. Now, obviously, if this were a string, your programming language would be like, "Uh uh! No way! You can't add 1 to "Bob"." EVEN IF the string is something like "5", it will not work. The string must be a number. So instead of having "5", have it equal 5. I have seen in some languages, including C, i++. This means the same exact thing as i=i+1, but it's a short term. In algebra, the >= and <= are combined, so they look like an < or > sign with a _ underneath. It means the same thing in programming, >= greater-than or equal to OR <= less-than or equal to. You can also use < and > alone.

 

While Loop:

i=0while i<5											  (Alternative: While		  CODE			Endwhile){  print "I is equal to: "+i+"."  i=i+1}

This checks to make sure i<5 and then does what's in the middle. You should get this:

I is equal to: 0.

I is equal to: 1.

I is equal to: 2.

I is equal to: 3.

I is equal to: 4.

Notice how it doesn't go to 5. This is because it says i<5, not i<=5. Also notice how it starts with 0 and not 1. If you said i=i+1 FIRST, it would only display 1-4 and not the 0. These little terms can change so much in your program, so make sure you pay attention to them!

IMPORTANT!:

Repeat/Until are used EXACTLY the same way, except for one thing! Repeat/Until does whatever is in between BEFORE checking, and then if it meets the requirements it will do it again. While and Endwhile/{} check first. Usually you want to use while, and that's why I displayed it first.

 

Now we are on the last topic in this - FOR LOOPS!

This way is really basic, the second is professional and is exactly how C does it's for loops too. (Of course in C, however, you must define variables ahead.)for i=1 to 10  print inext ifor i=1; i<=10; i++		 (Okay no basic will probably have ++ but just so you see how it works..){  print i}
Okay, so try this out for yourself or you will NEVER get it.

(FOR THE FIRST WAY ONLY! : the for loop says start at 1 and go to 10. The next part is just a way of knowing when to end the for loop code.)

(FOR THE SECOND WAY ONLY! : the for loop goes like this: set i to 1, while i is less than or equal to 10, i=i+1)

One last thing I need to talk to you about. This is STEP. Step tells the for loop to take leaps in it. For example, instead of counting to 100, why not count in tens like THIS:

10

20

30

40

50

60

70

80

90

100

Okay, that might be overdoing the example, but... Now you get it for sure!

for i=10 to 100 step 10  print inext i
One more note before I end this: when you do a for loop and you want to count backwards (E.g. 10, 5, 0, -5) use the step command and make it NEGATIVE. Some programming languages require you to use step to go negative. So, if you go backwards by 1, then you would do step -1. To do this professionally... Well, let me show you the difference:

for i=10; i<=100; i=i+1If you want to count by TENS do THIS:for i=10; i<=100; i=i+10See the difference?

ONE REALLY REALLY BIG NOTE!!! Make sure, that before you make any loops, ESPECIALLY DO loops, that you can get out of them! If not, then you make have a frozen computer, and depending on the programming language's power, you may have to shutdown because Control Panel (Ctrl-Alt-Delete) won't even come up. If you don't save (ANOTHER IMPORTANT NOTE), and you have a never ending do loop, you will lose all of your work! This is your only Warning!

 

 

 

 

This concludes my Programming Tutorial. There are lots more, and if you want them, put them in this forum and PM me. If you have any errors, put them DESCRIPTIVELY in here, and I will try to help. Don't forget to PM me!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.