Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Simplifying if else statement

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Simplifying if else statement

    What would be a better way to
    Simplify the following statement?

    IF (it's me)
    IF(I am here) ThEN
    IF ( case 1) THEN a
    ELSE If ( case 2) ThEN b
    ELSE c
    Endif
    Endif
    ElSE IF ( I am not here) ThEN
    IF ( case 1) THEN d
    ELSE IF (case 2) THEN e
    ELSE c
    ENDIF
    ENDIF
    ENDIF
    ENDIF


  2. #2
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: Simplifying if else statement

    not a java syntax, seems like a visual basic syntax.
    you can use a logical operator to simplify it

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simplifying if else statement

    How?

  4. #4
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: Simplifying if else statement

    let say I have this statement:
    int i = 0;
    if(i < 10) {
    if(i < 1) {
    if(i > -1) {
    System.out.println("I will simplify it");
    }
    }
    }

    simplified version:
    if(i < 10 && i < 1 && i > -1) {
    System.out.println("Simplified Version");
    }

    I think in vb its or and and.

Similar Threads

  1. Replies: 2
    Last Post: June 25th, 2013, 06:33 AM
  2. [SOLVED] A Loop statement and a switch statement issue
    By sternfox in forum Loops & Control Statements
    Replies: 13
    Last Post: March 7th, 2013, 04:19 PM
  3. Replacing an If statement with a Switch statement
    By logi in forum Loops & Control Statements
    Replies: 9
    Last Post: February 4th, 2013, 12:21 AM
  4. Simplifying Uml Class Diagram For System Comprehension
    By ArjanZ in forum Other Programming Languages
    Replies: 0
    Last Post: June 17th, 2012, 02:37 AM
  5. Help simplifying huge nested if statement?
    By racecar333 in forum Loops & Control Statements
    Replies: 6
    Last Post: November 1st, 2011, 01:03 AM