Questions tagged [local-variables]

Local variables have a limited scope, generally one function or one functional block.

Local variables have a limited scope, generally one function or one functional block.

Compare with global variables, which are accessible from any part of a program.

1302 questions
-1
votes
1 answer

local variable 'vehicle' referenced before assignment error encountered even though I assigned a list to the variable 'vehicle' just before that?

I have this code that encounters the error: local variable 'vehicle' referenced before assignment. But when I look through my code below, I have assigned a list to the vehicle variable in the if, elif statement, before the 'vehicle' is being…
-1
votes
1 answer

Can I assign value to variable or parameter after the execution code is defined?

I have a quite large script which is shrunk and simplified in this question.The overall principal is that I have some code that need to be run several times with only small adjustments for every iteration. The script is built with a major loop that…
MarJer
  • 87
  • 2
  • 9
-1
votes
1 answer

Please, can some one tell me what's wrong with this code?

Please, can some one tell me what's wrong with this code? #include using namespace std; int main() { int a[3], i; for(i = 0; i <= 3; i++ ) { a[i] = 0; cout << "i = " << i << endl; } …
-1
votes
1 answer

How make a variable scope in a html file

For expample i have following code with one php script ,then part of html code and then again php script. When i use variable $v,that variable saves value for then next part of php code. How can i write script to purufy variable value for the next…
-1
votes
1 answer

Is there a way to revert changes made to an element in a list?

I recently got help with fixing a function that changes elements in a list when printing said list. However, my program demands me being able to revert whatever changes I've made to an element in the list. Judging from the code, this should be…
Hvar01
  • 5
  • 2
-1
votes
1 answer

I wanted to print garbage value with an uninitialized variable

I wanted to print garbage value with an uninitialized variable. But when I tried to build the code on visual studio, it gives me a window and on the window there isn't option to ignore and execute. How can I execute this code? #include…
송효근
  • 47
  • 5
-1
votes
2 answers

Call a variable from inside a function into another function

I am trying to call a variable from inside a function into another function. I am running the code on node js and it's not working. Meanwhile, when I am trying the code on jsfiddle, it running normal. Any suggestion? thanks var array = []; …
-1
votes
1 answer

How can a local variable become not thread safe in Java?

I am learning Java multi threading and I read the following statement : Local variables are always thread safe. Keep in mind though, that the object a local variable points to, may not be so. If the object was instantiated inside the method, and…
alex
  • 71
  • 1
  • 5
-1
votes
1 answer

Unexpected output regarding local variable

I have created a local variable b in the function foo(). This function returns the address of the variable b. As b is a local variable to the functionfoo(), the address of the variable is not supposed to be there as the execution of the function…
-1
votes
1 answer

How to call global variable within if statement in Kotlin

a very simple question regarding Kotlin. What if a global variable (in function context) has the same name as a local variable declared within if statement. As you can see there are two msg variables, how to call outsider msg within if…
abidkhan303
  • 1,761
  • 3
  • 18
  • 31
-1
votes
1 answer

Are the pointers closed at the end of the local declaration?

I have a function and locally I have some pointers for file handling, reading zip files (using java.util.zip.ZipFile), streams etc. I must enclose all this work in a try{...}catch(...){...} statement, but when this fails I must close all the open…
e-info128
  • 3,727
  • 10
  • 40
  • 57
-1
votes
2 answers

How to pass a local array to another function call?

I am working on a project which requires certain actions be in their own functions. Right now, I must take the random values generated, and output them FROM an array. I have the values stored in numarray , but I don't know how I can call that array…
-1
votes
1 answer

unboundLocalError: local variable 'loopback' referenced before assignment

my code is as follows: import openpyxl from openpyxl import load_workbook def process(input="Input-Migration Table.xlsx", output_dir="\output"): dic_atn = {} for row in sheet2.iter_rows(min_col=3,min_row=2,max_col=3,max_row=17): for cel in…
tonyibm
  • 581
  • 2
  • 8
  • 24
-1
votes
1 answer

How to count in anonymous method?

I have this an implementation of class IntList. I'm am supposed to: Use the capability of the anonymous methods to refer to a local variable in their enclosing method and the defined "Act"-method to compute the sum of an IntList’s elements (without…
-1
votes
3 answers

Trouble initializing local/class variables

public class ClassName { public static void main(String[] args) { //code: depending on user input runs Methodname1(); } public static void MethodName1 { double kgs; double totalIn; //code: do/while…