+ 3

I don't understand why the answer is 120?

int foo=1; foo (int x=5; x<=50; x++) { foo*=x; for (int y=1; y<=5; y++) { if (x==y) {goto bar;} //goto=transfer control foo*=y; } } bar: Console. Write(foo) ;

14th Oct 2017, 4:45 PM
Š’Š°Š»ŠµŃ€Šøя
Š’Š°Š»ŠµŃ€Šøя - avatar
3 Answers
+ 4
In the first for-loop: foo Ɨ 5 = 5 Afterwards, in the second for-loop: foo Ɨ 1 = 5 foo Ɨ 2 = 10 foo Ɨ 3 = 30 foo Ɨ 4 = 120 Then y is 5, so equal to x, thus both loops are canceled and as a result "go to" is executed and foo is printed, which is now 120.
14th Oct 2017, 5:04 PM
Shadow
Shadow - avatar
+ 2
Could you share your code from Playground working?
14th Oct 2017, 4:59 PM
Daniel
Daniel - avatar
+ 2
Yes it isā˜ŗļø I am working through my mistakes. And then I'm looking for articles on this topic.
14th Oct 2017, 5:08 PM
Š’Š°Š»ŠµŃ€Šøя
Š’Š°Š»ŠµŃ€Šøя - avatar