Jumping in the code...

This is a discussion on Jumping in the code... within the C++ Programming forums, part of the General Programming Boards category; Hi, I would like to know an easy way to jump from one place to another in c++. Best regards! ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    20

    Jumping in the code...

    Hi,

    I would like to know an easy way to jump from one place to another in c++.

    Best regards! Adam

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Do you have a good (really, really good) reason to want to do so? One that isn't covered by the usual structures (if, while, for, etc.)?

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    You use flow controls such as:

    do, while, if, else, for, switch, goto

    Or functions.

  4. #4
    Registered User
    Join Date
    Sep 2008
    Posts
    20
    Well I don't really know if it is the best thing to do maby you could do it without jumping. But I'm curious if there is some commands that will enable jumping in the code.

  5. #5
    Registered User
    Join Date
    Sep 2008
    Posts
    20
    Quote Originally Posted by master5001 View Post
    You use flow controls such as:

    do, while, if, else, for, switch, goto

    Or functions.
    can you tell me more about the goto

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Yep. There sure are.

    Example:
    Code:
    int main(int argc, char **argv)
    {
      int i = 0;
    
      for_loop:
        if(i++ < argc)
        {
          puts(argv[i]);
          goto for_loop;
        }
    
      return 0;
    }

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I showed you, now to repay me you can promise not to ever make me correct one out of your code.

  8. #8
    Registered User
    Join Date
    Sep 2008
    Posts
    20
    thank you for showing me . But i still have some problems to create a for_loop: for exaple is there anything special you need to do? or just write the name like main: and then goto main; or?

  9. #9
    Registered User
    Join Date
    Sep 2008
    Posts
    20
    Figured it out now . now i have another problem!!!


    When i have the the jump command in a function but the header in the main function then you can't use the function to execute a jump. Is it possible to solve this ?

  10. #10
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    No. Are you an assembler language guy? Anything that requires you to jump into another function merits making whatever you are trying to jump to, to become its own function. I hope that made more sense than it did when I was reading it in my head -_-

  11. #11
    Registered User
    Join Date
    Sep 2008
    Posts
    20
    Quote Originally Posted by master5001 View Post
    No. Are you an assembler language guy? Anything that requires you to jump into another function merits making whatever you are trying to jump to, to become its own function. I hope that made more sense than it did when I was reading it in my head -_-
    so in other words, there are no ways of jumping like this:

    Code:
    #include <iostream>
    using namespace std;
    
    void jumping();
    
    int main(){
    
    cout << "hello";
    cout << "1";
    jump:
    cout << "2";
    jumping();
    
    return 0;
    }
    
    void jumping(){
    goto jump;
    }

  12. #12
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Correctomundo. You can technically achieve that kind of jump if you know how to dupe your compiler into letting inline assembler correctly calculate where to jump. But that is such a crapshoot its not even worth trying. My point is simply that you could make the lines that follow your jump label a separate function.

  13. #13
    Registered User
    Join Date
    Sep 2008
    Posts
    20
    okey, thanks.

    by the way, is it possible to clear all the text in a program?

  14. #14
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Which editor are you using?

  15. #15
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    system("cls"); Its insecure but about the only simple and portable way I can mention.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 08:34 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 11:20 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21