Thread: function terminator

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    61

    function terminator

    Hi! Every I need your help.
    How can I terminate a function?

  2. #2
    Registered User
    Join Date
    Sep 2012
    Posts
    68
    Use a return statement.
    If you are having an infinite loop inside,it may also cause a never ending function. Use "break" in that case.

  3. #3
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Return will work in the case of an infinite loop, if it is inside the body loop of course.
    When the code of the body of the function reaches an the keyword, it will terminate, no matter what.
    break keyword, will stop the loop and will transfer the flow of your code after the body of the loop.

    Of course, you can use a "return", even if your function is of return value void.

    Example.
    Code:
    void foo(int a)
    {
        if(a < 5)
            return;
        ...
    }
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  4. #4
    Registered User
    Join Date
    Dec 2012
    Posts
    61
    Thanks! )

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. array and string terminator
    By bobknows in forum C++ Programming
    Replies: 2
    Last Post: 03-08-2011, 07:45 PM
  2. newline and null terminator
    By dunsta in forum C Programming
    Replies: 2
    Last Post: 04-22-2010, 07:13 AM
  3. Terminator 4
    By abachler in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 05-23-2009, 11:15 PM
  4. Looking for null terminator
    By MiamiCuse in forum C Programming
    Replies: 3
    Last Post: 10-22-2005, 11:22 PM
  5. Terminator 3..nope
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 30
    Last Post: 07-18-2003, 07:42 AM