Thread: beginner question

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    2

    beginner question

    I see a lot of statements like:

    while (var != 0) {

    but isn't this equivalent to:

    while (var) { ?

    Is there a reason why people often use the first form?

    Thanks

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    2
    Can the admin please move this thread to C Programming forum.
    Thanks

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    *thread moved*

    Quote Originally Posted by manxmog
    Is there a reason why people often use the first form?
    It may be clearer, depending on the situation.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by manxmog View Post
    I see a lot of statements like:

    while (var != 0) {

    but isn't this equivalent to:

    while (var) { ?

    Is there a reason why people often use the first form?

    Thanks
    Both have the same meaning and you can use any form which ever you like. But generally to make it more clearer, specially for newbie's its written as in the first form.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner: Linked List question
    By WeatherMan in forum C++ Programming
    Replies: 2
    Last Post: 04-03-2008, 07:16 AM
  2. Quick IF statement question (beginner)
    By jim.rattlehead in forum C Programming
    Replies: 23
    Last Post: 11-29-2007, 06:51 AM
  3. beginner question
    By Barrot in forum C++ Programming
    Replies: 4
    Last Post: 08-19-2005, 02:17 PM
  4. Question About External Files (Beginner)
    By jamez05 in forum C Programming
    Replies: 0
    Last Post: 08-11-2005, 07:05 AM
  5. Beginner on Win32 apps, lame question.
    By Templario in forum C Programming
    Replies: 3
    Last Post: 11-06-2002, 08:39 PM