I'm confused | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

I'm confused

I was wondering what would happen if: int a = 2 ; for(a=3;;); Console.WriteLine(a) I've learned that for loop does instructions as follows: 1)It proceeds with first instruction 2)Then it checks the condition (the first semicolone) 3)If true proceeds with second instruction (second semicolone) 4)Otherwise if false breaks out of the loop and continues with code My idea was that the value would now be 3 but this is not the case.It turns out that there is an error that says"Unreachable code" Why?

29th Nov 2017, 8:46 PM
Patryk Orlik
Patryk Orlik - avatar
5 Answers
0
well you've created an infinite code. a is set as 3, but then there's no condition to check for, so since it'll always be true, the code will be stuck in the for loop forever.
29th Nov 2017, 9:51 PM
burrito77
burrito77 - avatar
0
System.out.println(3);?
29th Nov 2017, 9:53 PM
burrito77
burrito77 - avatar
- 1
So how do i get the value 3 on the screen?
29th Nov 2017, 9:52 PM
Patryk Orlik
Patryk Orlik - avatar
- 1
in c#
29th Nov 2017, 9:54 PM
Patryk Orlik
Patryk Orlik - avatar
- 1
Oh yeah pretty simple thanks for all help
29th Nov 2017, 9:56 PM
Patryk Orlik
Patryk Orlik - avatar