Results 1 to 8 of 8
Like Tree2Likes
  • 1 Post By JosAH
  • 1 Post By geonz

Thread: while (t.isAlive()){} Is it t.isAlive==true or t.isAlive()==false ?

  1. #1
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    116
    Rep Power
    0

    Default while (t.isAlive()){} Is it t.isAlive==true or t.isAlive()==false ?

    Sometimes it's written like,

    Java Code:
    While(flag){}
    How do you know if it is true or false? Is there a rule or convention for it?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,535
    Blog Entries
    7
    Rep Power
    20

    Default Re: while (t.isAlive()){} Is it t.isAlive==true or t.isAlive()==false ?

    The while( ... ) clause (and if ( ... ) clause etc) take a boolean expression which must be true to execute the body of the statement. A single boolean variable 'flag' is also a (simple) boolean expression, so if it's true the body of the statement executes.

    kind regards,

    Jos
    Zarah likes this.
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    geonz is offline Member
    Join Date
    Mar 2014
    Posts
    1
    Rep Power
    0

    Default Re: while (t.isAlive()){} Is it t.isAlive==true or t.isAlive()==false ?

    the implication when you say "while (something)" is that you mean while it is true.
    Zarah likes this.

  4. #4
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    116
    Rep Power
    0

    Default Re: while (t.isAlive()){} Is it t.isAlive==true or t.isAlive()==false ?

    @JosAH @geonz Thank you very much.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,535
    Blog Entries
    7
    Rep Power
    20

    Default Re: while (t.isAlive()){} Is it t.isAlive==true or t.isAlive()==false ?

    You have deleted your first reply, so I guess you understand it now; nevertheless: those conditions need to be boolean values; a boolean expression also is a boolean value after evaluation. The reason that just the value of t.isAlive() (either true or false) is enough, shows that t.isAlive() == true (or false) is just silly: true == true is true.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,618
    Rep Power
    5

    Default Re: while (t.isAlive()){} Is it t.isAlive==true or t.isAlive()==false ?

    And just to supplement this thread. It's not intuitive to some that you may also assign the result of a
    boolean expression to a boolean variable.

    So you can do:
    Java Code:
    boolean result = a > 3 && a < 10;
    result will be true or false depending on the value of a at the time the statement was evaluated.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  7. #7
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    116
    Rep Power
    0

    Default Re: while (t.isAlive()){} Is it t.isAlive==true or t.isAlive()==false ?

    You have deleted your first reply, so I guess you understand it now
    Yes, your answer explained it well, but I could not understand if properly at first.

    The reason that just the value of t.isAlive() (either true or false) is enough, shows that t.isAlive() == true (or false) is just silly: true == true is true.
    Agreed! Thank you.

  8. #8
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    116
    Rep Power
    0

    Default Re: while (t.isAlive()){} Is it t.isAlive==true or t.isAlive()==false ?

    And just to supplement this thread. It's not intuitive to some that you may also assign the result of a
    boolean expression to a boolean variable.

    So you can do:
    Java Code:
    1
    boolean result = a > 3 && a < 10;
    result will be true or false depending on the value of a at the time the statement was evaluated.
    Thank you, this is an interesting piece of information to know.

Similar Threads

  1. True and False Help
    By NBAPwns in forum New To Java
    Replies: 2
    Last Post: 12-19-2013, 12:55 PM
  2. How Do I Change True False Statements
    By RSdroid in forum New To Java
    Replies: 5
    Last Post: 12-16-2013, 03:53 PM
  3. how to balance true and false instances per id ?
    By aneuryzma in forum New To Java
    Replies: 1
    Last Post: 03-27-2011, 02:35 PM
  4. Prime Number - true , false
    By pinkdreammsss in forum Java Applets
    Replies: 11
    Last Post: 05-04-2010, 02:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •