Loop+ variable question

Hello, could anyone help me with this quest? I'm sitting on this since 3 hours and can't do anything.

I need to write a code for:

Line 1: 1
Line 2: 12
Line 3: 123
Line 4: 1234
Line 5: 12345
Line 6: 123456

and so on..

With the "for" loop.

Please help me out, and thank you for any help!

What lines? You need to explain it a bit better then this...

septillion:
What lines? You need to explain it a bit better then this…

I need the output in the serial monitor, a for loop that counts 1 to 9 like:

1: 1
2: 12
3: 123

Like the output from every previous line, before the last number.

I actually have 2 variables:

int i = 0;
int n = 0;

and “i” just counts from 1-10.

“n” should just print the previous output.

When is our assignment due to be handed in ?
Have you written any code using a for loop that tries to do what you want ?

UKHeliBob:
When is our assignment due to be handed in ?
Have you written any code using a for loop that tries to do what you want ?

I’m a completely new user, and don’t have any code right now.
So I have only some short basics about writing programming languages like C.

I actually have this code:

int i = 0;
int n = 0;
void setup()
{
Serial.begin(9600);
for(int i=1; i<10; i++)
{
Serial.print(“Line " );
Serial.print(i);
Serial.print(”: " );
Serial.print(n);
Serial.println(i);

}

}
void loop() {
// put your main code here, to run repeatedly:

}

but that’s just my start with this

Please read the How to use this forum post. Then go back and add code tags please.

And is it an assignment? Or can you explain why you want to do that?

septillion:
Please read the How to use this forum post. Then go back and add code tags please.

And is it an assignment? Or can you explain why you want to do that?

Could you explain me what exactly you don't understand from my question?

I actually have no real code yet, and just need some help or inspiration how I could do this, or maybe keywords for functions how to make it..

I get what you want now. But two things

  1. I asked you to tidy up your post and use code tags. Keeps everything nice and readable.
  2. I asked you WHY you want it? Because it seems pretty useless to me and it's definitely a XY-problem. Unless of course it's an assignment...

I’ve done it:

int i = 0;
int n = 0;
void setup()
{
Serial.begin(9600);
for(int i=1; i<10; i++)
{
Serial.print("Line " );
Serial.print(i);
Serial.print(": " );
for(int n=1; n <= i; n++)
Serial.print(n);
Serial.println("");

}

Congrats with finishing your assignment yourself :wink:

Now press Ctrl+T and see how it should have looked :wink:

PS The global int n is useless. It's never used :wink: You might want to remove that so you don't get annoying questions from your teacher.