+ 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 Antworten
+ 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