Циклы

Тема в разделе "Delphi - Базы данных", создана пользователем -, 9 июн 2008.

  1. Гость

    привет, народ! Я новечек в дельфи. Приведите пожалуйста не трудные примеры 3х циклов! я хотел бы примерно знать где можно, или нужно использовать :)
     
  2. etc

    etc Гость

    for + F1
    while + F1
    repeat + F1
     
  3. Гость

    а маленько поподробней ни как? :)
     
  4. etc

    etc Гость

    Мне кажется что подробнее некуда.
    Код (Text):
    A for statement, unlike a repeat or while statement, requires you to specify explicitly the number of iterations you want the loop to go through. The syntax of a for statement is for counter := initialValue to finalValue do statement or for counter := initialValue downto finalValue do statement where counter is a local variable (declared in the block containing the for statement) of ordinal type, without any qualifiers.
    initialValue and finalValue are expressions that are assignment-compatible with counter. statement is a simple or structured statement that does not change the value of counter.
    The for statement assigns the value of initialValue to counter, then executes statement repeatedly, incrementing or decrementing counter after each iteration. (The for...to syntax increments counter, while the for...downto syntax decrements it.) When counter returns the same value as finalValue, statement is executed once more and the for statement terminates. In other words, statement is executed once for every value in the range from initialValue to finalValue. If initialValue is equal to finalValue, statement is executed exactly once. If initialValue is greater than finalValue in a for...to statement, or less than finalValue in a for...downto statement, then statement is never executed. After the for statement terminates (provided this was not forced by a break or an exit procedure), the value of counter is undefined.

    For purposes of controlling execution of the loop, the expressions initialValue and finalValue are evaluated only once, before the loop begins. Hence the for...to statement is almost, but not quite, equivalent to this while construction:
    begin
    counter := initialValue;
    while counter <= finalValue do
    begin
    statement;
    counter := Succ(counter);
    end;
    end

    The difference between this construction and the for...to statement is that the while loop reevaluates finalValue before each iteration. This can result in noticeably slower performance if finalValue is a complex expression, and it also means that changes to the value of finalValue within statement can affect execution of the loop.

    Examples of for statements:

    for I := 2 to 63 do
    if Data[I] > Max then
    Max := Data[I];
    for I := ListBox1.Items.Count - 1 downto 0 do
    ListBox1.Items[I] := UpperCase(ListBox1.Items[I]);
    for I := 1 to 10 do
    for J := 1 to 10 do
    begin
    X := 0;
    for K := 1 to 10 do
    X := X + Mat1[I, K] * Mat2[K, J];
    Mat[I, J] := X;
    end;

    for C := Red to Blue do Check©;
     
  5. Гость

    Ну когда знаешь что и как, то это кажется легко
     
  6. mastershef

    mastershef Гость

    Держи студент.

    for i:=1 to 10 do
    ShowMessage('Это сообщение выводится в '+IntToStr(i)+' раз');


    i := 0;
    While(i<10) do
    begin
    Inc(i);
    ShowMessage('Это сообщение выводится в '+IntToStr(i)+' раз');
    end;

    i := 0;
    repeat
    Inc(i);
    ShowMessage('Это сообщение выводится в '+IntToStr(i)+' раз');
    until i=10;
     
Загрузка...
Похожие Темы - Циклы
  1. Maddy101d
    Ответов:
    3
    Просмотров:
    1.019
  2. Homka
    Ответов:
    12
    Просмотров:
    2.886
  3. Smile1995
    Ответов:
    2
    Просмотров:
    1.137
  4. Antonim
    Ответов:
    2
    Просмотров:
    1.473

Поделиться этой страницей