Thread: Understanding an if() statement.

Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1 Understanding an if() statement. 
    Registered Member
    CTucker's Avatar
    Join Date
    Oct 2008
    Posts
    2,422
    Thanks given
    263
    Thanks received
    281
    Rep Power
    343
    So, First I would assume you have basic understanding of variables, for this tutorial we are going to be using an integer as-well as a boolean.


    So, First we are going to declare our variables.

    Code:
    private boolean isBored = true;
    private int postCount = 0;
    Next, we are going to write our if-statement.

    Code:
    	        if(isBored)
    		{
    			postCount++;
    		}
    The above code reads as following, (If the boolean variable isBored is set to true, perform the actions below(Increase postCount by one)
    Here is another way to do the same exact thing.
    Code:
    		if(isBored == true)
    		{
    			postCount++;
    		}

    This also does the same thing, however brackets are not needed because there is only one line of code following the if() statement
    Code:
    		if(isBored)
    			postCount++;
    This also does the same thing, once again.
    Code:
    		if(isBored == true)
    			postCount++;
    Now, the next example does more than one thing inside of the if() statement, so brackets are required

    Code:
    	
    		if(isBored) 
    		{
    			postCount++;
    			isBored = false;
    		}
    The above code checks to see if the value of isBored is set to true, if it is, than it will increase my post count by one, and set the isBored boolean to equal false.



    If you couldn't tell, I was bored.
    This, Technically is a tutorial.
    Da..da.d.ad.a.... Dats all folkz
    Reply With Quote  
     

  2. Thankful user:


  3. #2  
    Registered Member Sirius_'s Avatar
    Join Date
    Nov 2013
    Age
    25
    Posts
    269
    Thanks given
    77
    Thanks received
    53
    Rep Power
    11
    Thanks for the contribution. I am sure it will clear some things up but overall common sense, at least for myself.
    Reply With Quote  
     

  4. #3  
    Registered Member
    CTucker's Avatar
    Join Date
    Oct 2008
    Posts
    2,422
    Thanks given
    263
    Thanks received
    281
    Rep Power
    343
    Quote Originally Posted by Sirius_ View Post
    Thanks for the contribution. I am sure it will clear some things up but overall common sense, at least for myself.
    Lol, Hopefully nobody comes to this tutorial with a serious intent to learn, however, if they do, I think it's explained.
    Reply With Quote  
     

  5. #4  
    Banned

    Join Date
    Mar 2013
    Posts
    3,036
    Thanks given
    82
    Thanks received
    375
    Rep Power
    0
    wow, look at those variables.
    Reply With Quote  
     

  6. #5  
    only shallow

    Join Date
    Apr 2011
    Age
    26
    Posts
    1
    Thanks given
    2,907
    Thanks received
    413
    Rep Power
    0
    thanks man I finally understand the if statements in my server. I have always looked at them and wondered what their true purpose was.
    Reply With Quote  
     

  7. Thankful users:


  8. #6  
    Registered Member Tx-Sec's Avatar
    Join Date
    Jan 2008
    Age
    30
    Posts
    520
    Thanks given
    34
    Thanks received
    15
    Rep Power
    68
    Omg this is to hard for me DD: lol just kidding nice one!
    Reply With Quote  
     

  9. #7  
    Renown Programmer

    Join Date
    Dec 2010
    Posts
    2,876
    Thanks given
    508
    Thanks received
    1,898
    Rep Power
    5000
    lol...
    never talk to me or my wife's son ever again
    Reply With Quote  
     

  10. #8  
    Ex-Staff

    Koy's Avatar
    Join Date
    Oct 2010
    Posts
    1,871
    Thanks given
    1,299
    Thanks received
    910
    Rep Power
    5000
    Not sure why we need such basic tutorials when Oracle has an extensive tutorial on Java. Good job nonetheless.
    Reply With Quote  
     

  11. #9  
    Registered Member

    Join Date
    Dec 2012
    Posts
    2,999
    Thanks given
    894
    Thanks received
    921
    Rep Power
    2555
    my booleans are the wrong way round
    Attached image
    Reply With Quote  
     

  12. #10  
    oof


    Join Date
    Aug 2012
    Posts
    3,150
    Thanks given
    2,847
    Thanks received
    857
    Rep Power
    2260
    if() method cant be found
    Reply With Quote  
     

  13. Thankful user:


Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 7
    Last Post: 05-27-2013, 04:48 AM
  2. Replies: 3
    Last Post: 11-06-2011, 03:06 AM
  3. Replies: 4
    Last Post: 06-22-2010, 09:07 PM
  4. If statement with an array?
    By Xenocide in forum Help
    Replies: 7
    Last Post: 11-21-2009, 02:59 AM
  5. Replacing lots of if statements with switch's.
    By Stanyer in forum Tutorials
    Replies: 6
    Last Post: 02-07-2008, 03:08 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •