Ask Question
7 January, 02:21

You are writing a program that defines a variable within a loop, and then tries to use that variable outside the loop. However, the program does not run as intended. What is the issue?

+5
Answers (1)
  1. 7 January, 04:13
    0
    The Variable is out of scope

    Explanation:

    In programming variables exists with scopes This could be local or global. When a variable is declared as a global variable it is available to all methods and procedures in the program. Java programming language as well as C+ + and several others use the open and close braces to define the scope in programs. consider the following example

    public class ANot {

    public static void main (String[] args) {

    int i = 0;

    while (i<10) {

    int sum = 0;

    sum = sum+i;

    }

    }

    }

    In this example, the variable i is global and can be assessed within the while loop but the variable sum is local to the while loop and cannot be assessed outside of it
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “You are writing a program that defines a variable within a loop, and then tries to use that variable outside the loop. However, the program ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers