beginner question

This is a discussion on beginner question within the C Programming forums, part of the General Programming Boards category; I see a lot of statements like: while (var != 0) { but isn't this equivalent to: while (var) { ...

  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
    21,794
    *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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 05: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, 07:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21