rewrite programs without gotos and breaks
-
-
i have this code guys: j = -3; for (i=0;i<3;i++) { switch (j+2) { case 3: case 2: j--; break; case 0: j += 2; break; default: j=0; } if (j>0) break; j = 3-i; } i want to write this without the breaks and goto how can i do it gurus? :sigh:
phokojoe
int j = 1; Remove everything else. It's better to do your homework yourself.
-Sarath. "Great hopes make everything great possible" - Benjamin Franklin
My blog - Sharing My Thoughts, An Article - Understanding Statepattern
-
i have this code guys: j = -3; for (i=0;i<3;i++) { switch (j+2) { case 3: case 2: j--; break; case 0: j += 2; break; default: j=0; } if (j>0) break; j = 3-i; } i want to write this without the breaks and goto how can i do it gurus? :sigh:
phokojoe
j = -3; int k = 0; for (i=0; (i < 3) && (j > 0); i++) { k = j + 2; if((3 == k) || (2 == k)) { j--; } else if (0 == k) { j += 2; } else { j = 0; } if(j <= 0) { j = 3 - i; } }