why does my loop only run once?

Jerry Murphy

This is my code

executeProgram:
    for (int i= 0; 1< memory.length; i++)
    {   
        String twoDigitMemory = String.format("%02d",memory[i] );
        System.out.print(twoDigitMemory +" ? +");
        accumulator = input.nextInt();

        if (input.nextInt() == -99999)
        {
            System.out.println("*** Program loading completed ***");
            System.out.println("*** Program execution begins  ***");
            break executeProgram;
        }
    }

This is my output. I enter 123.

***            Welcome to Simpletron!            ***
*** Please enter your program one instruction    ***
*** (or data word) at a time. I will display     ***
*** the location number and a question mark (?)  ***
*** You then type the word for that location.    ***
*** Type -99999 to stop entering your program    ***
00 ? +123

after entering 123 and pressing enter I expect the for loop to run again printing "00 ? +" but nothing happens, the input does get saved to the variable

SMA

You are expecting user to input number twice. Once you are storing in accumulater while the other just to compare the number like if (input.nextInt() == -99999) which is not needed. Instead you should use accumulater variable for checking like:

if (accumulater == -99999)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why does my for loop only appear to run once?

From Dev

Why does my loop rotate only once?

From Dev

Why is my while loop iterating only once?

From Dev

Why does this function only run once?

From Dev

Why does this bash for loop only iterate once?

From Dev

Why does the loop execute only once?

From Dev

Why does this loop execute only once?

From Dev

Why does setTimeout only print once in a loop?

From Dev

Why does my for loop come once?

From Dev

Run IF only once in FOR loop

From Dev

Why does my code run into an infinite loop?

From Dev

why setTimeout() only run my code once,at first time?

From Dev

Why does my loop iterate only twice?

From Dev

Why is the 'if' condition in my while loop only checked once?

From Dev

currency converter- why does my for loop in switch wont work? when i run my code only the first for loop works

From Dev

Why does a connect by expression in a FOR loop, execute only once?

From Dev

Why does a certain if statement only trigger once in a while loop?

From Dev

Why does my $watch only ever fire once?

From Dev

Why does my code only print nil once?

From Dev

Why does my asp update panel only refresh once

From Dev

Why for loop loops only once?

From Dev

Why does this code throw an IndexError only when run on my CA?

From Dev

Bash - How to make the loop run only once?

From Dev

Python : nested iteritems loop only run once

From Dev

Why does my loop only work correctly through the first iteration?

From Dev

PHP Why does my foreach loop only give 1 result?

From Dev

My for loop is only going through once

From Dev

Why will my C socket file transfer (server/client) program run correctly only once?

From Dev

why angularJs $watch only run once

Related Related

HotTag

Archive