Questions tagged as 'return'

4
answers

How do I return 2 or more values at a time in a method?

It is common to see examples of methods returning one value at a time. I've seen cases where you need to create a class just to package the data and to return more values.    Using generic classes would be the best way to return 2 or more  ...
asked by 06.04.2017 / 13:40
8
answers

Error: not all paths return a value

I would like to understand why my code is generating the error    not all paths return to value using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using...
asked by 03.05.2017 / 19:44
3
answers

What is the difference between 'yield' and 'return' in PHP?

I've been trying to get that doubt out, but to no avail. At first glance they looked like similar commands or they would be the same thing. After seeing some explanations, I was a bit confused and did not take my doubts. If they are not the s...
asked by 13.01.2016 / 16:31
3
answers

What is the difference between return and break in a switch case?

In some situations you need to practice switch case for optimization and improvement of code. I have an application developed for Android using Java, which in the case is used in both situations. Below I have an example using return...
asked by 05.01.2017 / 17:56
4
answers

Multiple return in C / C ++

Is it possible to return multiple values? For example: umafuncao() { int x = 1, y = 2; return x,y; } void main() { int a, b; a, b = umafuncao(); } I'm asking this question, because I built a code using this structure for a...
asked by 03.11.2015 / 14:25
4
answers

Two "return" in a function

How does it work if there are two (+) return in a Python function? Would you like to return the second value, or just the first one? Example: def soma(a, b): x = a + b y = 'qualquer coisa' return x return y     
asked by 21.09.2018 / 02:36
1
answer

When to use Supertype or Subtype on return method?

Suppose I have a method called " meuMetodo() " that returns an Object of type ArrayList<String> , I can make this method declare that it returns more concrete or more abstract types:    public ArrayList<String> meu...
asked by 10.05.2017 / 22:08
1
answer

What is the difference and advantages in using @@ IDENTITY and OUTPUT INSERTED.

I've always used @@IDENTITY to get the last identity value entered, as in the example below. create Proc [dbo].[Arquivos] @IdArquivo int, @IdArquivo_Out int output as begin Set Xact_Abort on Set Nocount on Begin Tran begin...
asked by 24.11.2015 / 16:52
1
answer

___ ___ erkimt Is there a difference between using "return" or "exit ()" to end the "main ()"? ______ qstntxt ___

%code% terminates running the application immediately. The %code% command exits the function, but when it is inside the %code% it will exit the application, including the value used in it will be returned to the one who called the application as an error code (zero is ok), as well as the function output.

Of course there is a difference in other functions, where %code% terminates application immediately and the command will return the execution stream to the calling function.

If both do the same thing in the described situation, does either use one or the other?

    
______ azszpr174313 ___

There is an important semantic difference in C ++. The %code% will close the scope and call all pending destructors. If the application is closed, rarely will the call of the destructors produce a different result, but technically it is possible for one of them to do something that is important to the end of the application, or to print relevant information for the user. >

Even though the action looks the same, the %code% function causes a premature exiting of the application. Then execution is terminated almost immediately. %code% finalizes static objects, but not destructors. The %code% and %code% neither does this and it closes on time.

There's a difference even in C if you have functions registered with %code% . These functions will always run no matter how the application is shutting down. But there will be undefined behavior if one of the linked functions in %code% has reference to some data in stack . Something like %code% and %code% . This is especially important in C. documentation

Note that the %code% function is not special and can be called within the application. In this case there will be an important difference since a %code% will not terminate the application, although in the context of the question this would not happen. But understand that if what you wrote will not be called in the operating system and this %code% is part of a module that will be loaded and used in another application, your module will terminate the application and not only your code if you use %code% , %code% will then be the most appropriate in most situations.

A call to %code% can be recursive, although it should not. Of course there is difference in this case, but it falls into what I said in the previous paragraph.

That's why you always have to choose the most semantically correct way . If you want to terminate the application immediately use %code% , otherwise use %code% . Many people say that if %code% is terminating the application, %code% is the most appropriate. Not everyone agrees, especially in C ++. That's why it's good to understand the workings, the implications of each and do not blindly follow rules.

I do not know if it counts as a difference, because it is a function, to use it, you need to use a %code% so that it is available, and if the code unit it contains would not enter the application, the executable will be a bit bigger. The command is always available.

    
___

exit() terminates running the application immediately. The return command exits the function, but when it is inside the main() it will exit the application, including the value used in it will be returned to the one who ca...
asked by 30.12.2016 / 13:15
2
answers

Why use only return, without returning any data?

Studying the code of a framework I came across the following code snippet: if (file_exists('lib/util/' . $className . '.php')) { include 'lib/util/' . $className . '.php'; return; } What is the purpose of using return wit...
asked by 28.05.2016 / 15:42