Name: Anonymous 2014-02-09 16:44
Lets see how we can replace an ugly goto with an elegant structured programming constructs.
Given an unstructured loop
line1:
printf("Dijkstra sucks cocks in hell.\n");
goto line1;
Without sacrificing any expressiveness, we can refactor the above code into:
line = 0;
while (line++ > 0)
{
switch(line)
{
case 1: printf("Dijkstra sucks cocks in hell.\n") break;
case 2: line = 1; break;
}
}
Not only did we killed goto, but also gained a way to address lines of code dynamically. I.e. we can compute the next value of "line" variable.
Given an unstructured loop
line1:
printf("Dijkstra sucks cocks in hell.\n");
goto line1;
Without sacrificing any expressiveness, we can refactor the above code into:
line = 0;
while (line++ > 0)
{
switch(line)
{
case 1: printf("Dijkstra sucks cocks in hell.\n") break;
case 2: line = 1; break;
}
}
Not only did we killed goto, but also gained a way to address lines of code dynamically. I.e. we can compute the next value of "line" variable.