Could anyone tell me for the code below, what is the role of each i and j ?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Could anyone tell me for the code below, what is the role of each i and j ??

#include <iostream> using namespace std; int main(){ int i,j; for(int i=1;i<=20;i++){ for(int j=1;j<=i;j++){ cout<<j; } cout<<"\n"; return 0; }

9th Sep 2017, 3:12 PM
RiGeL
RiGeL - avatar
5 Answers
+ 3
@RiGeL your for loop on "i" is missing its closing curly bracket, just notify you.
9th Sep 2017, 4:18 PM
Ipang
+ 3
i and J here are Iterators, they are here to make a loop. they are assigned a value, then you specify the expression that they have to fallow and typically you increment or decrement then in every loop step
9th Sep 2017, 3:49 PM
Paul
+ 2
@paul thank you alot
9th Sep 2017, 3:51 PM
RiGeL
RiGeL - avatar
+ 2
@Ipang thank you
9th Sep 2017, 4:20 PM
RiGeL
RiGeL - avatar
0
The inner loop will print all the values of j each time the outer loop runs, from 1 to the current value of i. So for i=4, it will print 1,1,2,1,2,3,1,2,3,4.
9th Sep 2017, 11:20 PM
josue