1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

All Loops and Its Syntaxes

Discussion in 'C' started by creative, Feb 19, 2010.

  1. creative

    creative New Member

    Joined:
    Feb 15, 2010
    Messages:
    87
    Likes Received:
    0
    Trophy Points:
    0
    Hi!
    After seeing For Beginners In C Topic, I thought to contribute all the loops syntax!
    so here we go....

    FOR LOOP
    SYNTAX
    Code:
    for(initial condition; checking condition; increment)
    {
    statement
    }
    for example.
    Code:
    for(i=0;i<=10;i++)
    {
    conunt = count + i;
    }
    :cool:
     
  2. creative

    creative New Member

    Joined:
    Feb 15, 2010
    Messages:
    87
    Likes Received:
    0
    Trophy Points:
    0
    sorry, the example will be
    Code:
    for(i=0;i<=10;i++)
    {
    count = count + i;
    } 
    
     
  3. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    Oh!
    Nice topic creative!
    ;)
    Welcome to forum!
    :D :D :D
     
  4. creative

    creative New Member

    Joined:
    Feb 15, 2010
    Messages:
    87
    Likes Received:
    0
    Trophy Points:
    0
    Thanks Pankaj!
    ----------------------
    Now I'm going to describe do-while loop!
    This loop is usually used to work on a single codition, such as "Add 1 with x if x greater than 5" etc.

    This loop is called "Exit Controlled" loop.
    Syntas:
    Code:
    do
      {
      statement;
      }
    while
      {
      Statement;
      }
    
    In this loop, if you look at the structure, you will find that, while processing it will process the first step and then it will check the condition! That is why its called "Exit Controlled Loop"!
     
  5. imported_crmahato

    imported_crmahato New Member

    Joined:
    Mar 9, 2010
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    few looping practice

    Code:
    void main()
    {
     int i=5;
     while(i>5)
     {
     printf("Cfanatic.com");
     }
    }
    o/p No output

    Code:
    void main()
    {
    int i=5;
    do
    {
    printf("Cfanatic.com");
    }while(i>5);
    }
    o/p Cfanatic.com
    Code within do-while loop execute once whether condition is true or false.
     
  6. imported_crmahato

    imported_crmahato New Member

    Joined:
    Mar 9, 2010
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    void main()
    {
     int i;
     for(i=0;i<100;i++);
     
      printf("Prashanna Bhoi");
    }
    
    o/p
    Prashnna Bhoi once.

    this is called delay loop
     
  7. imported_crmahato

    imported_crmahato New Member

    Joined:
    Mar 9, 2010
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    Indefinite loops

    for(i=0;i<10;i--)
    while(constant)
    {
    }
    e.g

    while(1)
    {
    printf("Hello");
    }
     
  8. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    hey crmahato!
    nice posts!
    ;)
     

Share This Page