lyric += " hate" just adds the word hate to the already existing string 'Haters gonna'. and it runs 5 times. With each run, it adds the word hate to the new string and stores it. So the first time it runs, the string becomes 'Haters gonna hate'. on the second run, it adds the word hate to the last stored string, the new string becomes "Haters gonna hate hate" and so on. Once the fifth run is executed, it prints the final string. You can try and put the print statement inside the loop body and will see that it does print the newly formed string with each new iteration.
I don't understand how in the nested loop the iteration repeats the number "1" a total of "12" times and the number "2" and so on. I'm breaking my head. That's the only part I don't get.
@edgar_roca: At the beginning, i =1 (to print 1s table). Then j for loop execution starts. Loop variable is j whose value is 1 at the beginning. Now i=1, j =1, in this first iteration 1 x 1 is 1 is printed. J increments to 2. In the second iteration of the j loop, i=1, j=2. Hence it prints 2 x 1 is 2. For the third iteration of the j loop, i=1, j=3. Hence it prints 3 x 1 is 3, until 12 x 1 = 12. Once 12 iterations of the j loop are completed, it comes out of loop, increment i to 2 and repeats j for loop with i= 2. Hence 2's table. I believe this should help.
you are a real swiftie
how these videos have only 2k views !!! thanks man
Had to watch this a couple of times and go over the reading to actually grasp my limited understanding of it.
nice
Why doesn’t the _ loop print out the entire string 5 times? I.e Haters gonna hate Haters gonna hate…etc?
lyric += " hate" just adds the word hate to the already existing string 'Haters gonna'. and it runs 5 times. With each run, it adds the word hate to the new string and stores it. So the first time it runs, the string becomes 'Haters gonna hate'. on the second run, it adds the word hate to the last stored string, the new string becomes "Haters gonna hate hate" and so on. Once the fifth run is executed, it prints the final string.
You can try and put the print statement inside the loop body and will see that it does print the newly formed string with each new iteration.
I don't understand how in the nested loop the iteration repeats the number "1" a total of "12" times and the number "2" and so on. I'm breaking my head. That's the only part I don't get.
@edgar_roca:
At the beginning, i =1 (to print 1s table).
Then j for loop execution starts. Loop variable is j whose value is 1 at the beginning. Now i=1, j =1, in this first iteration 1 x 1 is 1 is printed. J increments to 2. In the second iteration of the j loop, i=1, j=2. Hence it prints 2 x 1 is 2. For the third iteration of the j loop, i=1, j=3. Hence it prints 3 x 1 is 3, until 12 x 1 = 12. Once 12 iterations of the j loop are completed, it comes out of loop, increment i to 2 and repeats j for loop with i= 2. Hence 2's table. I believe this should help.
Taylor Swift should lean Swift))
Too bum for that
that was swift