answersLogoWhite

0


Best Answer

Yes. A variable declared inside the loop is a local variable for the code block enclosed by the {} statements of the for loop. The variable will not be available to be used by any code outside the code block.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

No, you cannot reference a variable defined inside the for loop outside the loop. This is because the variable goes out of scope outside the block, and therefore disappears. The only exemption is a non-class variable that is defined as static.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

A variable declared inside a for loop control, in fact, a variable declared inside of any statement block, is local to that block and is out of scope outside that block.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

Only if it is declared in the loop

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: A variable declared inside the for loop control cannot be referenced outside the loop?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Why static variables in a function have global extent?

A variable declared static outside of a function has a scope the of the source file only. It is not a global variable. A variable declared outside of a function and without the static qualifier would be a global variable.


What are Static variables in c?

A static variable in C is a variable whose value and memory allocation persists throughout the execution of the program. If the variable is declared at file scope (outside of any blocks) the static attribute means the variable is visible only to the file containing it, i.e. it can not be referenced through an extern reference in a different file.


Why all variables are declared with in the function?

It is not necessary to to declare variables inside the function in C. If you declare a variable inside a function, the variable becomes local for the function and another variable of same name can be declared in any other function, but you can not use the variable declared in other function. When you declare any variable outside the function body then the variable becomes global and can be used in any function of the program. Note: errno is an example for a variable declared outside any function.


What are local variables in Visual BASIC?

A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.


How can you declare global and local variable in pseudocode?

A local variable is a variable declared inside a construct, such as a class or function, while a global variable is a variable declared outside of any construct.

Related questions

Why static variables in a function have global extent?

A variable declared static outside of a function has a scope the of the source file only. It is not a global variable. A variable declared outside of a function and without the static qualifier would be a global variable.


What are Static variables in c?

A static variable in C is a variable whose value and memory allocation persists throughout the execution of the program. If the variable is declared at file scope (outside of any blocks) the static attribute means the variable is visible only to the file containing it, i.e. it can not be referenced through an extern reference in a different file.


Why all variables are declared with in the function?

It is not necessary to to declare variables inside the function in C. If you declare a variable inside a function, the variable becomes local for the function and another variable of same name can be declared in any other function, but you can not use the variable declared in other function. When you declare any variable outside the function body then the variable becomes global and can be used in any function of the program. Note: errno is an example for a variable declared outside any function.


What is the difference between variable declared inside the declaration part and variable declared in scriptlet part?

Variable declared inside declaration part is treated as a global variable, which means after translation of jsp file into servletthat variable will be declared outside the service method as an instance variablethe scope is available to the complete jspVariable declared inside a scriplet will be declared inside a service method as a local variable and the scope is with in the service method.


What are local variables in Visual BASIC?

A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.


What is Variable Scope?

The scope of a variable is the range, or area, in which a variable exists. // this c is global and can be referenced from anywhere int c = 1; void foo() { // this c is local to function foo and can't be referenced from the outside int c = 2; } void bar() { // if we try to reference c here, we get the value 1 from the global variable }


What is the difference between a static variable a global variable and a local variable?

A static variable is a variable allocated in static storage. A local variable is a variable declared inside a function. A global variable is a variable declared outside of any class or function. Note that local variables and global variables can both be allocated in static storage.


What are global variable?

Variables that are declared globally outside every program are called global variables.


How can you declare global and local variable in pseudocode?

A local variable is a variable declared inside a construct, such as a class or function, while a global variable is a variable declared outside of any construct.


How are global variable different from local variable in Visual BASIC?

A global variable is available for use throughout the program. It is normally declared outside any procedure. A local variable is only available for use in the procedure it was declared in. Most variables are local, but there will be occasions when you want different procedures to be able to use the same variable. This is when you use a global variable.


What is a valid variable declaration in PHP?

In PHP, you can declare a variable in several ways.In the global scope, or within a function, you can use:var $variable; // Creates an empty variable$variable = {something}; // declares, then assigns, the variableIn the object scope, a property operates like a variable:public $variable; // Creates an empty propertyprivate $variable; // Same thing, but can't be referenced outside the objectprotected $variable; // Similar, but can only be referenced in the object or any object extended by itpublic/private/protected $variable = {something}; // declares, then assigns a default value to, the property$this->variable = {something}; // if not declared, this will declare the property and assign the value to itYou can also create object properties from outside the object:$object->variable = {something}; // works just like $this->variableFinally, the arguments to a function are implicitly declared:function DoSomething ($variable) { ... } // declares and assigns $variableVariables in PHP are very flexible, mutable things. This is unlike some other languages that rely on strict type declarations for variables and other code constructs.


Can variable declared in one scriplet access in another scriplet?

No. Variables declared inside a scriptlet are like method local variables which are not accessible outside the scriptlet/method.