Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Java
  4. label in java

label in java

Scheduled Pinned Locked Moved Java
helpc++javaquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 9 Offline
    9 Offline
    9002code
    wrote on last edited by
    #1

    class jumping{ public static void main(String[] args){ int b,c; float a; b = 8; c = 2; test: { a = b/c; System.out.println("a first is "+a); while(a<=10){ b++; System.out.println("b in continue is "+b); if (b==12) { break test; } System.out.println("a final is "+a); continue test; } } } } i need final value of a is 6. but i can't? can you solve this? there are error in "continue test" statements, it give not a label? i need there code jump to label test like goto in C++? Kindly help me????

    R 1 Reply Last reply
    0
    • 9 9002code

      class jumping{ public static void main(String[] args){ int b,c; float a; b = 8; c = 2; test: { a = b/c; System.out.println("a first is "+a); while(a<=10){ b++; System.out.println("b in continue is "+b); if (b==12) { break test; } System.out.println("a final is "+a); continue test; } } } } i need final value of a is 6. but i can't? can you solve this? there are error in "continue test" statements, it give not a label? i need there code jump to label test like goto in C++? Kindly help me????

      R Offline
      R Offline
      rareseu
      wrote on last edited by
      #2

      why not just make test into a function or method and invoke it, im not sure what your code is supossed to do, but if it's supossed to continue executing untill b is 12, i've written an example :

      class jumping{
      public static void main(String[] args){
      int b,c;
      float a;
      b = 8;
      c = 2;
      test(a,b,c);
      }//main

      public void test(float a, int b, int c)
      {
      for( ; ; ){
      a = b/c;
      System.out.println("a first is "+a);
      while(a<=10){
      b++;
      System.out.println("b in continue is "+b);
      if (b==12)
      {
      System.out.println("a final is "+a);
      return;
      }

      }//while
      

      }//for

      }//test

      }//jumping

      ps : ident your code, it's very difficult to read otherwise, and use the code block ps2 : someone should disbale smileys in the code block

      9 1 Reply Last reply
      0
      • R rareseu

        why not just make test into a function or method and invoke it, im not sure what your code is supossed to do, but if it's supossed to continue executing untill b is 12, i've written an example :

        class jumping{
        public static void main(String[] args){
        int b,c;
        float a;
        b = 8;
        c = 2;
        test(a,b,c);
        }//main

        public void test(float a, int b, int c)
        {
        for( ; ; ){
        a = b/c;
        System.out.println("a first is "+a);
        while(a<=10){
        b++;
        System.out.println("b in continue is "+b);
        if (b==12)
        {
        System.out.println("a final is "+a);
        return;
        }

        }//while
        

        }//for

        }//test

        }//jumping

        ps : ident your code, it's very difficult to read otherwise, and use the code block ps2 : someone should disbale smileys in the code block

        9 Offline
        9 Offline
        9002code
        wrote on last edited by
        #3

        class jumping
        {
        public static void main(String[] args)
        {
        int b,c;
        float a;
        b=8;
        c=2;
        test:
        {

        a=b/c;
        System.out.println("a first is" +a);
        while(a<=10)
        {
        b++;
        System.out.println("b in continue is " +b);
        if(b==12)
        {
        break test;
        }
        System.out.println("a final is" +a);
        continue test;
        }

        }
        }
        }

        i want if b not equal to 12 then "a final is" is print. and b increase and also a is but it not? "kindly help me in java for using label/jump like goto in c++"

        R 1 Reply Last reply
        0
        • 9 9002code

          class jumping
          {
          public static void main(String[] args)
          {
          int b,c;
          float a;
          b=8;
          c=2;
          test:
          {

          a=b/c;
          System.out.println("a first is" +a);
          while(a<=10)
          {
          b++;
          System.out.println("b in continue is " +b);
          if(b==12)
          {
          break test;
          }
          System.out.println("a final is" +a);
          continue test;
          }

          }
          }
          }

          i want if b not equal to 12 then "a final is" is print. and b increase and also a is but it not? "kindly help me in java for using label/jump like goto in c++"

          R Offline
          R Offline
          rareseu
          wrote on last edited by
          #4

          [quote]i want if b not equal to 12 then "a final is" is print. and b increase and also a is but it not?[/quote] have you tried my code ? that's basically what it does

          9 1 Reply Last reply
          0
          • R rareseu

            [quote]i want if b not equal to 12 then "a final is" is print. and b increase and also a is but it not?[/quote] have you tried my code ? that's basically what it does

            9 Offline
            9 Offline
            9002code
            wrote on last edited by
            #5

            thanks. that is ok.. but it's not good solution for my problem. ok, i tell all thinks.... i develop a math program where a loop run apporoximat 800000 time and finaly value is came. in c++ there are goto statements and control jump to backword or forwared where we need. like that i need jump my code if my condition false and if true the loop exit.. so i can't use function. and it's a reason i send my code like that... so if u do please help me..

            N 1 Reply Last reply
            0
            • 9 9002code

              thanks. that is ok.. but it's not good solution for my problem. ok, i tell all thinks.... i develop a math program where a loop run apporoximat 800000 time and finaly value is came. in c++ there are goto statements and control jump to backword or forwared where we need. like that i need jump my code if my condition false and if true the loop exit.. so i can't use function. and it's a reason i send my code like that... so if u do please help me..

              N Offline
              N Offline
              Nagy Vilmos
              wrote on last edited by
              #6

              The goto statement is bad. When ever you call goto in a program a bunny will stub its toe. You can't be nasty to a fluffy bunny's toe can you? Loose the goto and learn to love and embrace methods and loops.#


              Panic, Chaos, Destruction. My work here is done.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups