if, then, and gotos

This is a discussion on if, then, and gotos within the C++ Programming forums, part of the General Programming Boards category; i did alot of programming on the TI-83-86 graphin clacs and got very used to the if, then, goto style ...

  1. #1
    Unregistered
    Guest

    if, then, and gotos

    i did alot of programming on the TI-83-86 graphin clacs and got very used to the if, then, goto style of programmin. is there anything like this in C++.
    im obviously a n00b so thanks for any help.
    bax

  2. #2
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Yes, but goto's are generally frowned apon. Instead of calling a goto, you would call a function.

    example:

    Code:
    int add(int a. int b)
    {
    	return a + b;
    }
    
    int subtract(int a, int b)
    {
    	return a - b;
    }
    
    if (myVariable == "add")
    {
    	int value = add(3, 2);
    } else {
    	int value = subtract(3, 2);
    }

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Yes, they are if, else, and goto's in C++. Some simple examples would be as follows:

    Code:
    if( variable != 53 )
    {
         // Do something here
    }
    else
    {
         // Do this other thing instead
    }
    
    Also there is else if ( ) // for multiple if's... Goto's I believe work like this.
    
    {   // Start of some function
    
         // Something
         goto EXIT;
    
    
    EXIT:
         return (0);
    }
    I think generally goto's are considered poor programming so I never use them. I have never encountered a situation where I could not use something else to avoid a goto situation. But any other questions, just post.
    Last edited by MrWizard; 04-02-2002 at 06:21 PM.

  4. #4
    Seņor Member
    Join Date
    Jan 2002
    Posts
    561
    Don't use goto in C++!

  5. #5
    Registered User Liam Battle's Avatar
    Join Date
    Jan 2002
    Posts
    114
    oh dear god, unless you are writting a bios for a piece of hardware, NEVER EVER USE GOTO...
    your boss will kill you...

    one entry point and exit point... thats the key....
    LB0: * Life once school is done
    LB1: N <- WakeUp;
    LB2: N <- C++_Code;
    LB3: N >= Tired : N <- Sleep;
    LB4: JMP*-3;

  6. #6
    Unregistered
    Guest
    thanks alot for all the help.
    I have another question already though.
    Is there a clrscn (clearscreen) type command that can be used
    for programms only running in the dos prompt?
    thanks again,
    bax

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

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