11,663
questions
-2
votes
1
answer
34
views
Why am I getting a return value of None when I used return, but it works in all other situations I have tried? [duplicate]
# Sample Code
import datetime
sample = {
"Eat": [
datetime.datetime(2024, 9, 13, 2, 0),
datetime.datetime(2024, 9, 13, 3, 0),
"2024-09-13 20:43:35.440898&...
0
votes
0
answers
21
views
how to execute both return and redirect on next js api response
I'm working on a Next.js project where I want to redirect the user after a successful login, but also return the user data for further processing. Here’s my code:
if (response.data.user) {
...
-3
votes
0
answers
58
views
Trying to develop solution to reverse integer problem. it works while on code but does not work with test cases [closed]
class Solution {
public int reverse(int x) {
int temp=x;
int rev=0;
int result=0;
if(x>=0){
x=x;
}else{
x=-x;
}
while(x!=0){
int rem=...
-4
votes
0
answers
34
views
Python Multiple Ifs in a Return Statement? [duplicate]
I know that it is possible to make a return statement with an if but I am trying to make easy Codewars problems into one line return statements. What I know is:
return x if expression1=true else y
...
0
votes
1
answer
23
views
Comparing a selection
Hi please can you help.
I'm trying to select the last 200 rows in my database, then compare 2 fields in each row, and return each whole row where there is only 1 instance. So, all rows that have more ...
1
vote
1
answer
131
views
If there is [[noreturn]], then why there is no [[always_return]]?
If there is [[noreturn]] (C2X, n3301), then why there is no [[always_return]]?
The semantics of [[always_return]] may be the following:
A function declared with an [[always_return]] attribute shall ...
0
votes
0
answers
63
views
In Wordpress is it necessary to use return; after wp_send_json_error?
After having looked around a bit and not having understood anything I still have the question whether it is necessary to use
return;
after a wp_send_json_error(); I read that the wp_send_json_error ...
-1
votes
2
answers
60
views
In a recursive Python function, why does it matter what parameters are returned?
I thought I understood recursive functions but realised I don't actually understand what is happening under the bonnet
Running this Python code to generate a triangular series gives the expected ...
1
vote
1
answer
87
views
Why it has to have a default return value when implementing binary insertion using recursion?
The searchInsert function return the index where the target should be based on the value. Why it should have the line
return -1;
in the following code? I thought I included all the possible outcomes ...
0
votes
0
answers
22
views
Returning None not breaking out of function
@staticmethod
def log_in():
logged_in = False
while not logged_in:
username = input("Username: ")
if not(User.user_exists(username)):
...
0
votes
0
answers
18
views
Why return false and not simply return is giving the expected behaviour?
My goal is to limit the length of an input of type number to just one number. For this I used the response of Vikasdeep Singh in this SO answer which in my case is working perfectly. I also had to ...
1
vote
2
answers
104
views
What variables are destroyed when calling exit(), based on Microsoft's docs?
I was trying to figure out the differences between terminate(), exit() and abort(), and Microsoft's
C++ program termination documentation came up in my Google search that compares exit vs abort vs ...
0
votes
1
answer
101
views
Return from recursion
Hello in my program I need to implement a recursive descent and return from recursive calls. Input data (100, 37). I was able to print the recursive descent, but I do not understand how to print the ...
0
votes
1
answer
110
views
When using a function to add a new node to a linked list, why do i need to return the new node? [duplicate]
Currently I am trying to create a linked list.
Here is the class I am using to create nodes:
class node{
public:
int item;
node* ptr_next;
node(int new_item = 0, node* ...
1
vote
1
answer
63
views
z80 assembler ret z; and a; ret
I have the following Z80 asm code (from pokemon legacy crystal)
CheckOnWater::
ld a, [wPlayerStandingTile]
call GetTileCollision
sub WATER_TILE
ret z
and a
ret
i was wondering ...
-5
votes
1
answer
46
views
Calculating the volume of a square
package Pyramid;
import java.util.Scanner;
public class SquareVolume {
public static void main(String[] args) {
double length = 0;
double width = 0;
double height = 0;
...
0
votes
3
answers
79
views
difficulty to understand the code, and maybe the concept itself (recursion problem)
this code below is from Grokking Algorithms book that is an exercise for the functional programming/recursion and an application for the D&C concept. the function finds the maximum number in a ...
-4
votes
1
answer
52
views
Function returning "None" [duplicate]
I wrote the short program below while practising how to use a custom function.
def square(num):
square==(num**2)
print(square(10))
return
I was expecting that when I call the function:
...
0
votes
0
answers
18
views
Nginx config skipping "if" condition
I have the following snippet in my nginx config file:
set $condition 0;
if ($arg_d ~* "IY86O") {
set $condition "A";
}
if ($request_uri !~ ^/pre-qualify) {
set $condition &...
0
votes
2
answers
47
views
Return statement isnt working and is giving an error in react js [closed]
I was writing this code where I am making some Modals so I wrote this code
import { useContext } from "react"
import { ModalContext } from "../ModalProvider"
import { ...
0
votes
1
answer
43
views
Store result of json request in a variable [duplicate]
I need to store a value of json response to use in another function.
I have this code:
const url_moodle = "https://xxxxx/xxxxx/app/appmoodlejson.php";
var moodleEmail = function (email){
$...
0
votes
0
answers
25
views
How can I pass a variable to my other function in flask backend?
I am currently building a vocabulary trainer for my assignment. I'm using flask and javascript in the backend.
One function retrieves the vocabulary ID primary key from the database, and I need it in ...
0
votes
0
answers
48
views
Why is it ok to return a reference to a function's default argument? [duplicate]
#include <iostream>
//class for testing**
class T
{
public:
void print() { std::cout << "hello\n"; }
~T() { std::cout << "~T\n";}
};
//function for ...
0
votes
1
answer
86
views
How can I redirect to an action but not first of view, but another part of view
this is my action to add new address on a step form , step form have 4 part that have a main Id for form , I want in the second tab add to new address and if method was success return to my view, but ...
1
vote
0
answers
40
views
"Not all code return a value" when loop returns [duplicate]
I'm a coding beginner and have a question on how to return to an array in C#. When I wrote the code, it popped out an error msg "not all code return a value".
[HttpGet]
[Route("api/J3/...
1
vote
1
answer
48
views
Compilation and return values of infinite loops with try-catch blocks
I encountered this problem when experimenting with file I/O. This method compiles:
public static int testMethod1() {
try {
while (true);
} catch (Exception e) {
...
0
votes
1
answer
64
views
Pass multiple variables from function to use further in script
I am trying to create a variable of true/false within a function and then use that variable later in the script. My current function has a return which works, but i can not seem to understand how to ...
1
vote
0
answers
29
views
Powershell returns some random values from a function [duplicate]
I wrote a function that should return an object or $null. What the code does instead, is it's returning an array which contains $policyTxtBlock (input param), and then either the object or null.
Why ...
0
votes
0
answers
30
views
Have os.system() or subprocess.call() without return or error [duplicate]
I'd like a way for os.system() or subprocess.call() not return ANY text in the terminal.
I want to have code running in the background that closes out of an application whenever it opens, and I ...
0
votes
3
answers
170
views
C 'String Array' Function Returns Empty
I'm writing this program to enumerate every file in the directory to practice using pointers because I am new to the concept and the C language. The return statement to **getFiles() comes back empty ...
2
votes
1
answer
111
views
C# Best way to break out of multiple nested functions with high performance
*Sorry, I will continuously edit my article to make my description clearer to express my question.
This may also cause some inconvenience.
I have an automation program used to control other ...
0
votes
1
answer
46
views
Carriage returns in userform textbox
I am passing a string through to a userform textbox, and cannot get the text to recognise where I want carriage returns.
The string contains several 'vbNewLine' entries (I've tried alternatives like ...
0
votes
1
answer
35
views
Postgres which is the differene between returns and OUT when there is only one OUT
In question How to generate an array of given size, with one field populated? I have been instructed to write instead of a "returns" an "OUT" statement for a function definition.
...
0
votes
0
answers
24
views
What is the purpose of "Return" in Python when i could just use a print in a function? [duplicate]
I am learning about Python and trying to get my head around why i should use the return statement instead of just printing the result.
My course covers the syntax but does not elaborate on WHY you ...
0
votes
0
answers
38
views
Clarify my understanding of returning an object with attribute created on heap [duplicate]
so I have overloaded the addition operator like this:
outside of the class, I have
template <typename ValueType>
class array_vec;
template <typename ValueType>
array_vec<ValueType> ...
0
votes
0
answers
23
views
How can return an array in C#
I want to create a program that enters the values of that array using getArray() function and displays the entered values of array by using a function named displayArray(). So for this I have to ...
-1
votes
2
answers
101
views
How to pass on values when converting a recursive function to an iterative one with stack and while loop
EDIT: My initial recursive code was incomplete, as I did not multiply by f(l, r) the sum of the two recursive branches.
Given a function f(l, r) that computes something from the nodes (l, r) of a ...
0
votes
0
answers
37
views
Copy a message from a discord channel and send it to another program
How do I write a function inside a class that will return a message from a discord channel. I need to store that message in a variable to send it to another program.
This is the class:
import discord
...
0
votes
1
answer
20
views
Argument of a function and return statement
import java.util.*;
class Main{
public static int factorial(int a){
int fac=1;
for(int i=1;i<=a;i++){
fac=fac*i;
}
return fac;
}
public ...
3
votes
0
answers
25
views
Named return and code coverage in Solidity
Context
While aiming at 100% code coverage and 100% SolHint compliance I am experiencing some difficulties in combining the gas-named-return-values rule from SolHint, with the branch coverage of the ...
0
votes
0
answers
75
views
vanilla javascript :: throw new Error inside async function is not executing
I want to terminate the script and literally throw new Error
when the web server cannot find the resource file (404).
the console confirm that the response.status indeed is 404
but I am not getting ...
-3
votes
1
answer
61
views
Return statement error during compilation , without using try catch method [duplicate]
import java.util.*;
public class Main {
public static Void main(String[] args) {
Scanner sc =new Scanner(System.in);
int j = sc.nextInt();
for (int i = 0; i < j; i++) {...
0
votes
0
answers
36
views
Why script from Jupyter is not working in VS Code? [duplicate]
Why this python code cannot be executed in VS Code but works in Jupyter notebook? how do you print the output?
def get_even(numbers):
return [num for num in numbers if not num % 2]
get_even([1, ...
1
vote
0
answers
50
views
Clang possibly skipping line(s) of code while compiling
#include <stdio.h>
#include <math.h>
#define MAX_BITS 32
int counter = 0, dec_eqv = 0;
int runcounter = 1;
int binToDec(char *bit)
{
printf("dec_eqv is %d\n", dec_eqv);
...
0
votes
0
answers
36
views
Return struct containing borrowed value in rust
I am trying to contruct a new NetworkManager from a function, but it takes a reference to another variable which is also created in the same scope.
fn test() -> NetworkManager<'_> {
let ...
2
votes
1
answer
49
views
Why does the following base case for recursion in C not work?
I am practicing recursion function in C. The question is to create a recursive function to print a sum of all of the elements (int) in an array without changing the main function.
I know how to write ...
0
votes
2
answers
52
views
Why does return statement return's default value [duplicate]
I try to check the user input which should be either 0 or 1.the program returns true if it is 1 and return false if it is 0 and if any other integer values except(1 and 0) it again call itself to get ...
0
votes
0
answers
43
views
Unable to filter and get just the return variable from a .ps1 script execution
$scriptPath = "${{ github.action_path }}\get_details.ps1"
$ServerName = "remoteserver777"
$returnArray = & "$scriptPath" -mypass ${{ inputs.mypass }} -myuser ${{ ...
0
votes
1
answer
42
views
Return partial View if model state was not valid
I have a slider that has a registration form, I create the form as a partial View .
this is the method of create registration form:
Get method:
public IActionResult CorporationRegisterRequest()...
0
votes
1
answer
82
views
Does this use of "new Mystring" create a memory leak? C++
Before anyone start saying that I should use std::string, this is an exercise part of a course, and I'm trying to learn here, not just to make something work.
The code runs ok, but I'm trying to ...