Can someone help me write this simple while loop?

It would make it easier to have a separate loop control variable, yes.

For what values should your loop control variable start and stop?

You really only need one loop.

I am not sure, can you show me?

Do you have a while loop that you have written before that uses a increasing or decreasing integer control variable?

I think the n++; is the control variable, but how do I get it to stop the loop?

n is not a good choice for the control variable in this case, and the above loop doesn’t work correctly.

Do you have a while loop that you have written before that uses a increasing or decreasing integer control variable and works?

1 Like

Can you please just show me what to do? I am really stressed and this loop is due tomorrow.

We don’t just give people answers here. I can help you build code, but just giving you the answer does not actually help anyone.

I really don’t know what to do.

Do you have an example of a while loop that works in your notes somewhere that we can start with?

1 Like

No, I don’t have an example.

I’m not certain how this is possible if you are in a class that expects you to write a while loop for a homework assignment.

Anyways,
I found this example by putting “Java while loop” into a search engine:

Example

int i = 0;
while (i < 5) {
  System.out.println(i);
  i++;
}

So, how could we modify this loop to print all numbers from -n to n?

I am still not sure.

Have you tried running this code? What values will this loop print?
[https://repl.it/repls/NimbleIndianredKernelmode#Main.java]

It prints out
0
1
2
3
4

Ok. So why does it start at 0? Why does it stop at 4? Can you make it stop at 5 instead?