It's worth noting that this would be an infinite loop. Think about it: if you go back to 0 every time i
reaches 7, how would it ever bet the case that i == 10
? How would you break out of the loop? This may be a case of the XY problem - i.e. you probably don't actually want to do what you say you want to do here.
If you really want this to occur in an infinite loop, just do this:
while (true) {
for (int i = 0; i <= 7; i++) {
if (i == 7) {
// ..
}
}
}
Actually, I'm slightly baffled as to why you bother with the "for" loop at all in this case if you're only doing something in the case where i = 7
; why bother with the for loop at all and just put the action in an infinite loop?
Also, if you're doing this on the UI thread, it'll appear to "hang" the UI because the UI thread won't ever be able to do anything other than service your for loop. Users won't even be able to close it normally.
Finally, as other people have pointed out, never use goto
, it's a bad practice - Microsoft shouldn't have even included it in the language.