From 5602e0466104744b9692e001944a1eba26489f1f Mon Sep 17 00:00:00 2001 From: Jeremy Kaplan Date: Fri, 6 Dec 2019 10:28:21 -0800 Subject: [PATCH] Stop using exceptions for control flow --- 2019/day5/intcode.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/2019/day5/intcode.rb b/2019/day5/intcode.rb index 2674a4e..9f7ff73 100644 --- a/2019/day5/intcode.rb +++ b/2019/day5/intcode.rb @@ -49,8 +49,6 @@ module Intcode end end - class DoneExecuting < StandardError; end - class Executor def initialize(mem) @mem = mem @@ -59,10 +57,7 @@ module Intcode def run(&user_input) loop do - tick(&user_input) - rescue DoneExecuting - # TODO: Stop using exceptions for control flow - return + return if tick(&user_input) == :done_executing end end @@ -85,7 +80,7 @@ module Intcode when 8 equal! when 99 - raise DoneExecuting + :done_executing else raise StandardError, "unexpected opcode: #{opcode}" end