Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 11th, 2007, 04:50 AM
Registered User
 
Join Date: Nov 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to exit from function

Hello
Can any one suggest how to exit from the middle of Function the function when certain condition became true.


for example

function1
{
         ------some code-----
         . . . .
         if (condition1==true)
             exit function

         ----- some code----

}


dont want to use else.

 
Old January 11th, 2007, 04:53 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You can use

return useFullValueToReturn;

For example, if your function is of type bool, you can return false or true, depending on what makes the most sense.

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old January 11th, 2007, 06:24 AM
Registered User
 
Join Date: Jan 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Example
private void fn1(int x, int y)
{
   Your statements;
   // for some reason you want to pull out at the beginning itself
   return;
   ..........
    ....
   // if you want to exist function
   return;
}

Example
private int fn1(int x, int y)
{
    int i=0;
   Your statements;
   ..........
   // For some reason you want to exit here
    return i;
    ....
   // if you want to exist function
   return i;
}







Similar Threads
Thread Thread Starter Forum Replies Last Post
exit from a void function Necromancer26 C# 3 October 16th, 2012 09:06 AM
on exit mohiddin52 Access VBA 2 July 10th, 2007 09:28 AM
exit from for-each preethi.s XSLT 1 September 8th, 2006 05:37 AM
Exit Application King_ General .NET 0 February 23rd, 2006 10:30 AM
How do we exit from a function in JavaScrip ? MisbahAnsari Javascript 1 November 28th, 2003 07:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.