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.


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

Results 1 to 3 of 3

Thread: If-goto Loop

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Thanked 0 Times in 0 Posts

    Default If-goto Loop

    Hey guys,

    I have an assignment due for thursday and this is one of the questions

    Here is a for loop:
    1. for i equals 1 to 10
    2. an instruction
    3. another instruction

    Rewrite this loop in if-goto language.

    The problem is, I have no idea what if-goto language is :/ it;s really confusing me, hoping someone can offer me some help

  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Thanked 619 Times in 561 Posts
    Blog Entries

    Default Re: Java question

    if-goto is what it sounds like:

    If something is true, goto somewhere else.

    For example:

    1. ask user for input
    2. if invalid input: Goto 1
    3. process input

    This will keep asking the user for inputs until what they enter is valid.

    In current programming practice goto should be avoided as it has a tendency to produce "spaghetti code" (code that's hard for humans to read/understand). It has it's uses and is a must in assembly/machine language, but you really shouldn't be programming at that level if you don't have to.

    Obligatory XKCD comic on GOTO

    --- Update ---

    Please don't post the same question under multiple categories. I've moved stuff around so you only have one thread.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Thanked 0 Times in 0 Posts

    Default Re: If-goto Loop

    Thanks for the reply, sorry about posting in multiple categories.

Similar Threads

  1. Replies: 1
    Last Post: November 1st, 2012, 07:54 AM
  2. Challenging Java Question: Test your Java skill by grouping these terms
    By karthickk3 in forum Java Theory & Questions
    Replies: 3
    Last Post: July 18th, 2012, 10:10 PM
  3. Java EE Question
    By djl1990 in forum Java Theory & Questions
    Replies: 2
    Last Post: May 12th, 2012, 12:42 PM
  4. help for this java question
    By marlontoyo in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 20th, 2011, 08:09 PM
  5. Java Question
    By NiCKYmcd in forum Java Theory & Questions
    Replies: 1
    Last Post: August 25th, 2010, 08:47 AM