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

Couting the attempts in a 'while' loop?

Discussion in 'C#' started by HannahMar, Feb 18, 2010.

  1. HannahMar

    HannahMar New Member

    Joined:
    Feb 18, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi there, I am VERY new to programming and I was wondering if there was a way to count the attempts it took a user to guess a correct number (in a while loop) and then display that number back to the console?
     
  2. servalsoft

    servalsoft New Member

    Joined:
    Apr 17, 2010
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    int count = 0;
    while (condition)
    {
    //do something
    ++count; //this line increase the count every time the loop is called
    }
     
  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:
    ++count or count++ is depends on what of calculation or logic you are coding!
    because they works in different way!
    :)
     
  4. servalsoft

    servalsoft New Member

    Joined:
    Apr 17, 2010
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    That's right unless neccessary, I usually used pre-increment, ++count; because it performs less calculations hence it is much faster....
     
  5. sai111

    sai111 New Member

    Joined:
    Nov 23, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    tankhuuuuuuuuuuu
     

Share This Page