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. Code to convert from C# to Java (with goto)

Code to convert from C# to Java (with goto)

Scheduled Pinned Locked Moved Java
csharpjavahelpquestion
5 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.
  • K Offline
    K Offline
    Kujtim Hyseni
    wrote on last edited by
    #1

    Hello, I have the following code in C#:

    public void encrypt()
    {
    SeaX11:
    ...
    if (Cnt != 47) goto SeaX12; //cjne Cnt,#47,SeaX12 ;when halfway through, swap keys, other key schedule and other key used
    goto SeaX21; //ljmp SeaX21

        SeaX12:
            ...
            goto SeaX11; //ljmp  SeaX11
    
        SeaX21:
            ...
            if (Cnt != 1) goto SeaX22; //cjne  Cnt,#1,SeaX22
            goto SeaX23; //sjmp  SeaX23
        SeaX22: goto SeaX21; //ljmp  SeaX21
        SeaX23:
            return;
    

    }

    to convert in Java. Can anyone help with this?

    G L 2 Replies Last reply
    0
    • K Kujtim Hyseni

      Hello, I have the following code in C#:

      public void encrypt()
      {
      SeaX11:
      ...
      if (Cnt != 47) goto SeaX12; //cjne Cnt,#47,SeaX12 ;when halfway through, swap keys, other key schedule and other key used
      goto SeaX21; //ljmp SeaX21

          SeaX12:
              ...
              goto SeaX11; //ljmp  SeaX11
      
          SeaX21:
              ...
              if (Cnt != 1) goto SeaX22; //cjne  Cnt,#1,SeaX22
              goto SeaX23; //sjmp  SeaX23
          SeaX22: goto SeaX21; //ljmp  SeaX21
          SeaX23:
              return;
      

      }

      to convert in Java. Can anyone help with this?

      G Offline
      G Offline
      gettgotcha
      wrote on last edited by
      #2

      http://stackoverflow.com/questions/2430782/alternative-to-goto-statement-in-java[^] Java reserves goto but does not define it. However, statement labels do exist, and in a strange twist break and continue were enhanced to accept them. You can only jump out of local blocks, but break operates on any block – not just loops. This makes Java break almost the full equivalent of C# goto. Java switch operates on (boxed or unboxed) primitives and enums, and since Java SE 7 also on strings. You don’t need to qualify enum case values with the enum type as in C#. Java allows fall-through from one case to the next, just like C/C++. Use the compiler option -Xlint:fallthrough to warn against missing break statements. There is no equivalent to C# goto targeting a case label.

      1 Reply Last reply
      0
      • K Kujtim Hyseni

        Hello, I have the following code in C#:

        public void encrypt()
        {
        SeaX11:
        ...
        if (Cnt != 47) goto SeaX12; //cjne Cnt,#47,SeaX12 ;when halfway through, swap keys, other key schedule and other key used
        goto SeaX21; //ljmp SeaX21

            SeaX12:
                ...
                goto SeaX11; //ljmp  SeaX11
        
            SeaX21:
                ...
                if (Cnt != 1) goto SeaX22; //cjne  Cnt,#1,SeaX22
                goto SeaX23; //sjmp  SeaX23
            SeaX22: goto SeaX21; //ljmp  SeaX21
            SeaX23:
                return;
        

        }

        to convert in Java. Can anyone help with this?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        I would suggest you start from scratch and redesign your program. With all those goto statements it's impossible to figure out the logic.

        Veni, vidi, abiit domum

        K 1 Reply Last reply
        0
        • L Lost User

          I would suggest you start from scratch and redesign your program. With all those goto statements it's impossible to figure out the logic.

          Veni, vidi, abiit domum

          K Offline
          K Offline
          Kujtim Hyseni
          wrote on last edited by
          #4

          I am afraid that I can't rewrite the code since it is ported from 8051 assembler to C#. I thought we could do something with

          if/else

          to

          goto

          ?

          L 1 Reply Last reply
          0
          • K Kujtim Hyseni

            I am afraid that I can't rewrite the code since it is ported from 8051 assembler to C#. I thought we could do something with

            if/else

            to

            goto

            ?

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Since there is no goto statement in Java, you really do not have much choice.

            Veni, vidi, abiit domum

            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