function terminator

This is a discussion on function terminator within the C Programming forums, part of the General Programming Boards category; Hi! Every I need your help. How can I terminate a function?...

  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
    55
    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, 08:13 AM
  3. Terminator 4
    By abachler in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 05-24-2009, 12:15 AM
  4. Looking for null terminator
    By MiamiCuse in forum C Programming
    Replies: 3
    Last Post: 10-23-2005, 12:22 AM
  5. Terminator 3..nope
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 30
    Last Post: 07-18-2003, 08:42 AM

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