While Loop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

While Loop

Hello! I need to write a code that displays: 1 12 123 1234... depending on the number of rows. I wrote the code attached, but don’t know how to modify it to output what i have written above. It has to be two nested while loops! Thanks! https://code.sololearn.com/c42n6s0Bcd1M/?ref=app

1st Oct 2018, 4:12 AM
Miqaela Weller
Miqaela Weller - avatar
3 Answers
+ 3
ok, it should be a simple modification just change for (int i = 0; i <= numRows; i++) { ... } to int i = 0; while (i <= numRows) { ... i++; } and do the same process for the inner loop.
1st Oct 2018, 4:38 AM
Isaac Pace
Isaac Pace - avatar
+ 2
I changed it to a for loop which makes more sense here: https://code.sololearn.com/cFDmKMNcT9yb/?ref=app
1st Oct 2018, 4:28 AM
Isaac Pace
Isaac Pace - avatar
+ 1
Oh, sorry, i forgot to mention it has to be two nested while loops. i know a for loop would be better in this case, but my professor wants while loops.
1st Oct 2018, 4:30 AM
Miqaela Weller
Miqaela Weller - avatar