Thursday, October 22, 2015

Embarcadero/Borland Delphi Programming Language Looping/Iteration

Embarcadero/Borland Delphi Programming Language Looping/Iteration

Note:
Perulangan =  looping
Lata yang akan diulang = word(s) to be repeated
Jumlah perulangan = number of iteration

Jenis perulangan = iteration type
Hasil perulangan = iteration result

Form design:
 

Properties:
 
Components
Properties
Value
Form1
Caption
Program 3 Perulangan
Label1
Caption
Kata yang akan diulang
Label2
Caption
Jumlah perulangan
Label3
Caption
Jenis perulangan
Label4
Caption
Hasil perulangan
Edit1
Text
Kosongkan/clear
Edit2
Text
Kosongkan/clear
ComboBox1
Caption
Repeat Until

Items
Repeat Until
For To Do
While Do
Memo1
Lines
Kosongkan/clear

Delphi program:


procedure TForm1.ComboBox1Change(Sender: TObject);
var
  i : integer;
begin
  Memo1.Clear;

  if ComboBox1.Text = 'Repeat Until' then
  begin
    i := 1;
    Repeat
      Memo1.Lines.Add(IntToStr(i) +'. '+ Edit1.Text);
      i := i + 1;
    Until (i > StrToInt(Edit2.Text));
  end;

  if ComboBox1.Text = 'For To Do' then
  begin
    For i := 1 To StrToInt(Edit2.Text) Do
    begin
      Memo1.Lines.Add(IntToStr(i) +'. '+ Edit1.Text);
    end;
  end;

  if ComboBox1.Text = 'While Do' then
  begin
    i := 1;
    While (i <= StrToint(Edit2.Text)) Do
    begin
      Memo1.Lines.Add(IntToStr(i) +'. '+ Edit1.Text);
      inc(i);
    end;
  end;
end;

Output:


ShadowOfBdg© - All rights reserved. 

No comments:

Post a Comment