Results 1 to 2 of 2
  1. #1
    narniafosho is offline Member
    Join Date
    May 2011
    Posts
    1
    Rep Power
    0

    Default Qurstion about if statements

    I have a question about writing if statements.
    I am trying to write a basic menu for a program. There are 4 different options to choose from. I have created a int variable that is equal to what the person typed in.

    int selection = keyboard.nextInt();
    System.out.println("Do you want option 1?");
    System.out.println("Do you want option 2?");
    System.out.println("Do you want option 3?");
    System.out.println("Do you want option 4?");

    if(selection = 1){
    <statements>
    }
    else if(selection = 2){
    <statements>
    }
    else if(selection = 3){
    <statements>
    }
    else(selection = 4){
    <statements>
    }


    my question is how do I go back to the top of the if statements after the user selects an option. For example, if they type in 1 for the selection variable, the if statement will end. But I do not want the if statement to end. I want to run through it and let the user select their option, but after all the code runs for that if statement i want to go back to the top of the if statement and let the user make more selections from those same if statements again. Any help would be greatly appreciated. Thanks in advance

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

Similar Threads

  1. Help with IF Statements and GUI
    By university123 in forum New To Java
    Replies: 8
    Last Post: 10-14-2010, 05:38 AM
  2. if else if statements
    By Allspark in forum New To Java
    Replies: 9
    Last Post: 09-28-2010, 07:50 PM
  3. Help with if else statements
    By np2392 in forum New To Java
    Replies: 2
    Last Post: 09-24-2010, 02:25 AM
  4. if else statements
    By sweetpea123 in forum New To Java
    Replies: 4
    Last Post: 04-12-2010, 08:02 PM
  5. Help with if-else statements
    By porchrat in forum New To Java
    Replies: 4
    Last Post: 03-23-2009, 05:24 PM

Tags for this Thread

Posting Permissions

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