Hmm. you could even try studying
php. Check out the
manual on the PHP site. It covers some of the basics of programming.....Ah-ha! I recommend you look at
Sun's Java as a beginning language. It's pretty good.
Either php or java. your decision. php doesn't require a compiler....so.....
If you *do* decide to start using php, check out phpdev, from firepages.
I orinigally had about 3000 lines of tutorial typed here, but I'm going to replace it with a much more basic tutorial.
Many programming languages contain the following similar things:
1.
Variables. These are used to hold values. You can store almost any kind of data in these little guys. There are different kinds of variables, and you use them in different ways. Some variables hold random streams of characters (like a sentence). These are
STRINGS. Some hold numbers. These can be integers, decimals, money values, fractions..whatever....numbers. There are other variable types too. But the basic variable holds a value so you can either reuse it over and over again, or manipulate it.
2.
Control Structures. These are used to do things to the values in different ways. Huh? Well...some examples:
a (while) loop.... you can continuously make the program do something until a condition is met (like when a password is entered correctly).
a (for) loop....you know when this loop will end, but you want to perform it that many times. So you perform the same block of code a set number of times. Example:
Let's say I wanted to print a sentence in PHP 10 times...I could do this:
PHP Code:
<?php
for ($x=1;$x<=10;$x++) {
print "This is my sentence.";
}
?>
How does that work? I'll break it down:
<?php - this says...hey server...we're starting to write some php code here!
the "$x=1" - this sets a variable called "x" and sets it's value to 1.
(variables in php are recognized because they start with a dollar sign)
$x<=10 - this says....do the code inside the curly braces { and } until the value of "x" equals 10.
$x++ - this is what's called an
operator. Its another thing common to programming languages. It's a method of manipulating the values of variables. In this particular instance, it says that every time the loop finishes and starts again, ++ (add 1) to the value stored in "x" (any time you see "++", it could also be "+1")
print "This is my sentence."; - I think this is kind of self explanatory
?> - this tells the server that we're done with the php code.
3.
Methods & Functions - This is fairly simple, but can be difficult to understand. A method or a function is simply a set of code, that does something. You could write a function that adds 1 to a variable. Example:
PHP Code:
<?php
function add_one($x) {
$x++;
return $x;
}
?>
I'll explain thew new parts.
add_one($x) - this gives the function a name ("add_one") and then everything in the parenthesis is what the function expects to receive as input. In this case, it is going to accept some value and store it into the variable "$x" .
$x++; - we discussed this above. It makes the value stored in $x equal whatever it did plus 1. (aka, it
increments the value of "x");
return $x; - somewhere in our code, we made a
function call (we told the server that we wanted to run the function). Now a function can (it doesn't have to) return some value back to the part of code that called it. An example:
PHP Code:
<?php
$x = 1;
$y = add_one($x);
print $y;
function add_one($x) {
$x++;
return $x;
}
?>
What's going on? Start at the top.
$x = 1; - make the variable 'x' store a value of 1
$y = add_one($x); - make the variable 'y' store the value of whatever the function 'add_one' returns, when it is given the variable '$x' (in this case, the number 1)
print $y; - this simply makes the server print out the value stored in the variable y. What's that value? well....it's the value returned by function add_one. In this case, it returns the number 2. It accepted the value stored in $x (in this case, the number 1) and then added 1 to it, and then spit the new value back out.
These are some of the fundamentals. I'd HIGHLY recommend reading through the
php manual mentioned above. It's purty good.