3 ms·
Rather than using nested while loops with labels, why not use one big while loop and a switch statement? This seems cleaner and would allow jumping ahead, rathe
by tlrobinson 17y ago
Rather than using nested while loops with labels, why not use one big while loop and a switch statement? This seems cleaner and would allow jumping ahead, rather than just behind.
Labels "[lbl] foo" would become "case 'foo':goto_label=false;" and gotos "goto foo;" would become "goto_label='foo'; continue goto_loop;".
Example:
var goto_label='top';
goto_loop: while(goto_label) {
switch(goto_label) {
case 'top': goto_label=false;
...
goto_label='foo'; continue goto_loop;
...
case 'foo': goto_label=false;
...
}}
Not perfect, but better.
edit: scratch that, labels within other control structures won't work, only top level ones.