i to p

Embed Size (px)

Citation preview

  • 8/8/2019 i to p

    1/4

    Theforloop.

    The for loop statement is used to execute a set of statements

    repeatedly for a fixed number of times. It is also know as counter loop.

    The structure of this loop is different from both the while and do- while loops. It hasthe following parts.

    I. InitializationII. Condition

    III. Increment or decrementIV. Body of the loop

    The general syntax of the for loop is:

    (Starting point) (Ending point)

    For (initialization; condition; increment/decrement)(1) In initialization part, the value in the variable is assigned when control

    enter into the loop first time. New variables can also be declared and

    initialized in this part.

    For example.

    For (int a=6, b=5; a

  • 8/8/2019 i to p

    2/4

    The diagram of the for loop is given

    below:

    False

    True

    Program .no.1

    Write a program to print the multiplication table of a number

    entered from the keyboard.

    #include

    #include

    using namespace std;

    int main ()

    {

    int table,mul,c;

    Initialize variables

    Text

    Condition

    Incremental ex ression

    Exit

    Body of loop

  • 8/8/2019 i to p

    3/4

    couttable;

    for(c=1;c

  • 8/8/2019 i to p

    4/4

    sum=sum+n;

    cout