begin for I := 1 to 1000 do begin
Label1.Text := InttoStr(I); for ch := ‘a’ to ‘z’ do// This is a nested loop
Label2.Text := ch; // It will count through the alphabet 1000 times end;
I:= 0; while I < 5 do begin
Label2.Text := ‘I is less than 5′;
I := I +1; // Inc(I); end; end;
The full code is below, and here are the two theams of the video:
The “for” loop. Used to do something several times. The $i counts and in our case the $decimals tells the computer how many times to do it.
for ($i=1; $i < $decimals; $i++)
{
// The code to execute goes here.
}
The “if” and “else” statements
if ($i = 1 )
{ // If $i is equal to one, then // The code to execute goes here
} else// If $i does not equal one, do this
{
// If $i is equal to one, then // The code to execute goes here
}
Actual code from the video
for ($i=1; $i < $decimals; $i++)
{
if ($i % 2 == 0)// This is an even number
{ $denominator = $denominator + 2; $pi_calc = $pi_calc + 1 / $denominator;
} else // This is an odd number
{
$denominator = $denominator + 2;
$pi_calc = $pi_calc – 1 / $denominator;
}
Variables in PHP use the “$‘. If we define a variable, then we pick a name for it and then put the $ in front of it. So if our variable was LastName, we would define it in PHP as $LastName;
We can then assign it a value by: $LastName = “Smith”; Some other examples from the video are as follows.
$a = 2; $b = 3.4; $c = $a + $b; // Adding numbers
$firstName = “John”; // Storing strings of text $lastName = “Smith”; $fullName; $fullName = $firstName . $lastName; // Add the text together $this->Label1->Caption = $fullName;
// Integer data types :
Byte; // 0 to 255
ShortInt; // -127 to 127
Word; // 0 to 65,535
SmallInt; // -32,768 to 32,767
LongWord; // 0 to 4,294,967,295
Cardinal; // 0 to 4,294,967,295
LongInt; // -2,147,483,648 to 2,147,483,647
Integer; // -2,147,483,648 to 2,147,483,647
Int64; // -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Char; // Holds a single character, small alphabet
WideChar; // Holds a single character, International alphabet
AnsiChar; // Holds a single character, small alphabet
shortString; // Holds a string of up to 255 Char’s
String; // Holds strings of Char’s of any size desired
AnsiString; // Holds strings of AnsiChar’s any size desired
WideString; // Holds strings of WideChar’s of any size desired