Learning to Program C++ Builder Tutorial – For and While Looping

int i = 0;
char ch;

for (i = 0; i <= 10; i++) {  // Normally we know how many iterations we want, even if it is dynamic
Label1->Text = i;

  for (ch = ‘a’; ch <= ‘z’; ch++) {
Label2->Text = ch;
}
}

i = 0;
while (i <= 5) {     // Normally, we don’t know how many iterations, like reading a file or a web page
Label1->Text = i;
i = i + 2;
}

Learning to Program Delphi Tutorial Looping – for and while loops

var
ch: Char;
I: Integer;

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;

Learning to Program Delphi Tutorial – If then else – Pascal

< Previous                                                                                                                                  Next >

a := 3;
b := 4;
c := 5;

if a > b then
Label1.Text := ‘c is greater than b’

else if b = 2 then
Label1.Text := ‘b is equal to 2′

else if b < c then
Label1.Text := ‘b is less than c’

else if b <> c then
Label1.Text := ‘b is not equal to c’

else if a + b = c then
Label1.Text := ‘a + b is equal to c’

else
Label1.Text := ‘a and b are not greater b or c’

Learning to Program C++ Tutorial 3 – if and else statements – C++ Builder

< Previous Video                                                                                                                Next Video >

// Check for even or odd
if (5 / 3 == 9) // Test condition
{
// If the condition is true then do this
Label1->Text = “Even”;
}

else {
Label1->Text = “Odd”;
}

Learning to Program PHP Tutorial 3 – Calculating Pi – RadPHP

< Previous Video                                                                                                   Next Video >

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;
}

}
$pi_calc = 4 * $pi_calc;
$this->Label1->Caption = $pi_calc;

// pi = 3.14
// pi = 4 * (1 – 1/3 + 1/5 – 1/7. . . )

Learning to program 1 – Pascal Lazarus – Install a free IDE

Next Video >

Learning to program Delphi tutorial 2 – Variables – Pascal – Rad Studio XE2

< Previous                                                                                                                                  Next >

Delphi Tutorial Code:

var
i: Integer; // 1, 2, 3, -1, -2, -3
d: real; // 1.2, 3.4, -6.7
s: string; // store text
begin
i := 5;
d := 56.34;
s := ‘Hello There’;

Label1.Text := FormatFloat(‘###,###.##’, d); //IntToStr(i); StrToInt(Edit1.Text)
end;

 

Numbers

// 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

// Decimal data types :
Single;   //  7  significant digits, exponent   -38 to +38
Currency; // 50+ significant digits, fixed 4 decimal places
Double;   // 15  significant digits, exponent  -308 to +308
Dec4 : Extended; // 19  significant digits, exponent -4932 to +4932

Strings

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

Learning to program Delphi tutorial 1 – Hello World – Pascal

Next >

Delphi Tutorial Code:

Label1.Text := Edit1.Text;

Learning to program C++ tutorial 2 – Variables – C++ Builder

C++ Tutorial Code:

int a; // Integer 1, 2, 3, -1, -2
a = 5; // After creating the space, put something in it

double b = 5.7; // Create the space that can hold decimals.
double c = 9.5;

char t = ‘h‘; // hold a character
String u = “Hello There“; // hold a String of characters

Label1->Text = u;

Name Description Size Range
char Character or small integer. 1byte signed: -128 to 127
unsigned: 0 to 255

short int

Short Integer. 2bytes signed: -32768 to 32767
unsigned: 0 to 65535
int Integer. 4bytes signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
long int Long integer. 4bytes signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
bool Boolean value. It can take one of two values: true or false. 1byte true or false
float Floating point number. 4bytes +/- 3.4e +/- 38 (~7 digits)
double Double precision floating point number. 8bytes +/- 1.7e +/- 308 (~15 digits)
long double Long double precision floating point number. 8bytes +/- 1.7e +/- 308 (~15 digits)
wchar_t Wide character. or 4 bytes 1 wide character
Page 1 of 3123