Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualBacterius

Posted 30 November 2012 - 07:02 AM

how would you replace the goto in this bit with an exception

[source lang="cpp"]int doWork(){ for (int bar =0; bar < 100; ++bar) { for(int foo = 0; foo < 100; ++foo) { if (foo * bar == 100) {                return 1; } } }    return 0;}// ...if (doWork()) printf("%d", 100);[/source]

Or, use a boolean flag for each loop... works too but it's ugly.

EDIT: I guess foo wasn't the best function name, lol.

#3Bacterius

Posted 30 November 2012 - 06:41 AM

how would you replace the goto in this bit with an exception

[source lang="cpp"]int doWork(){ for (int bar =0; bar < 100; ++bar) { for(int foo = 0; foo < 100; ++foo) { if (foo * bar == 100) { return 0; } } } return 1;}// ...if (doWork()) printf("%d", 100);[/source]

Or, use a boolean flag for each loop... works too but it's ugly.

EDIT: I guess foo wasn't the best function name, lol.

#2Bacterius

Posted 30 November 2012 - 06:40 AM

how would you replace the goto in this bit with an exception

[source lang="cpp"]int doWork(){ for (int bar =0; bar < 100; ++bar) { for(int foo = 0; foo < 100; ++foo) { if (foo * bar == 100) { return 0; } } } return 1;}// ...if (foo()) printf("%d", 100);[/source]

Or, use a boolean flag for each loop... works too but it's ugly.

EDIT: I guess foo wasn't the best function name, lol.

#1Bacterius

Posted 30 November 2012 - 06:40 AM

how would you replace the goto in this bit with an exception

[source lang="cpp"]int foo(){ for (int bar =0; bar < 100; ++bar) { for(int foo = 0; foo < 100; ++foo) { if (foo * bar == 100) { return 0; } } } return 1;}// ...if (foo()) printf("%d", 100);[/source]

Or, use a boolean flag for each loop... works too but it's ugly.

PARTNERS