Results 1 to 6 of 6

Thread: Java - goto or continue

  1. #1
    Join Date
    Dec 2009
    Posts
    292

    Java - goto or continue

    Hello,
    my code looks as follows:
    Code:
    Public static void hd(String []args)
    {beginning:
    inst1;
    inst2;
    ...
    instn;
    switch
    {
    case1: inst1; break;
    CASE2: inst2; break;
    case3: inst3; break;
    }}
    I would add to each cell a control like "you want to return to the beginning?" I found a little difficulty doing that especially since there is no goto in java.
    can you help me? Thank you in advance.
    Last edited by Miles Runner; 16-01-2010 at 10:40 AM.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Java - goto or continue

    Hello,
    I think the following could would suit your needs, just have a look
    Code:
    Public static void hd(String []args)
    {
    boolean go =true;
    while (continue){
    beginning:
    inst1;
    inst2;
    ...
    instn;
    switch
    {
    case1: inst1; break;
    CASE2: inst2; break;
    case3: inst3; break;
    Would you continue = continue();
    }}
    }

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Java - goto or continue

    Hello,
    I use this code to perform the task which you have mentioned below
    Code:
    Public static void hd(String []args)
    {beginning:
    inst1;
    inst2;
    ...
    instn;
     
    while ( continues )
    { 
      continues = 0 ;
     
      switch
       {
         case1: inst1; break;
         CASE2: inst2; break;
         case3: inst3; break;
       }
    
    }

  4. #4
    Join Date
    Dec 2009
    Posts
    292

    Re: Java - goto or continue

    Hello,
    I did try this code, but it fails
    Code:
    Public static void hd (String [] args)
    {
    String = ch;
    do
    {beginning:
    inst1;
    inst2;
    switch (choice)
    	{
                   box 1:break;
    	 box 2:break;
                   }
    System.out.System.out.println("return to start?");
    chx = keyboard.unString();}
    while(chx ==yes);}
    This does not work, it just requires the hearing the answer and then he goes, what's wrong?

  5. #5
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Java - goto or continue

    Hello,
    I read your code and have modified it, just check it, it works now.
    Public static void hand (String [] args)
    {
    String = ch;
    do
    {beginning:
    inst1;
    inst2;
    switch (choice)
    {
    box 1:break;
    box 2:break;
    }
    System.out.System.out.println("return to start?");
    chx = keyboard.unString();}
    while(chx.equals(yes));}

  6. #6
    Join Date
    Dec 2009
    Posts
    292

    Re: Java - goto or continue

    Hello,
    while(chx.equals(yes));}
    Thanks, the code works perfect, but I have any query in mind, what was wrong in my code, If I am not wrong you have used the inbuilt function to compare the string and I have done it manually, does this makes difference.
    while(chx ==yes);}
    Or is it I am somewhere else wrong. Any suggestion on this.

Similar Threads

  1. Setup cannot continue
    By Norika in forum Office Setup
    Replies: 4
    Last Post: 30-01-2010, 11:46 PM
  2. How to use the continue statement in java program?
    By Luz in forum Software Development
    Replies: 4
    Last Post: 23-01-2010, 08:40 PM
  3. Repetition problem with On Error Goto xx
    By KAMAL60 in forum Software Development
    Replies: 3
    Last Post: 30-10-2009, 06:20 PM
  4. To use goto statement or not while coding the program?
    By YatinK in forum Software Development
    Replies: 3
    Last Post: 19-02-2009, 07:19 PM
  5. VB script - GOTO Do Loop - possible to acheive?
    By Bosch in forum Software Development
    Replies: 5
    Last Post: 12-01-2009, 08:25 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,430,195.02956 seconds with 17 queries