General Programming 101
Web Development August 26th, 2009Programming is all logical and wrapped within a syntax. A syntax is like a structure, or requirement of rules to follow in the way it's written.
Kind of like driving down the road and staying in your lane, and using your blinker. Don't break those rules or something bad and unexpected might happen.
Here are two conditional statements that you can assume what they do easily:
if ()
else ()
You also have operators, which compare and do things much like in math:
=
*
!
The key to all programming is called looping, or loops. Loops repeat themselves:
foreach ()
for ()
while ()
You also assign variables, these are usually different in most languages so here are two different:
var jesse
$jesse
If you want to create a simple program here is how you could do one.
1. Assign variables. (The semi-colin at the end means it's the end of that piece)
$jesse = 24; $joe = 25;
2. Create a condition using and operator
if ($jesse > $joe)
{
echo 'Jesse is older than Joe';
}
3. Create and alternative condition, if that ones is false
else
{
echo 'Joe is older than Jesse';
}
4. Create an array for fun
$names = array('Joe', 'Jesse', 'Jenny', 'Justine');
5. Create a loop to print the array
foreach ($names as $name)
{
echo $name . '
';
}
6. Cool, here is all the code. It looks easier when you know what you're dealing with!
$jesse = 24;
$joe = 25;
if ($jesse > $joe)
{
echo 'Jesse is older than Joe';
}
else
{
echo 'Joe is older than Jesse';
}
$names = array('Joe', 'Jesse', 'Jenny', 'Justine');
foreach ($names as $name)
{
echo $name . '
';
}

Recent Comments