Class: Peruby::Op::CFor
- Includes:
- LoopExecution
- Defined in:
- lib/peruby/op/loop.rb
Overview
C-style for loop.
Instance Method Summary collapse
-
#initialize(initializer, condition, step, body, continuation, label) ⇒ CFor
constructor
rubocop:disable Metrics/ParameterLists.
- #run(env, _context) ⇒ Object
Methods inherited from Base
#argument_cells, #local_slot, #lvalue, #run_subroutine, #to_callable, #warning_directive?
Constructor Details
#initialize(initializer, condition, step, body, continuation, label) ⇒ CFor
rubocop:disable Metrics/ParameterLists
19 20 21 22 23 24 25 26 |
# File 'lib/peruby/op/loop.rb', line 19 def initialize(initializer, condition, step, body, continuation, label) # rubocop:disable Metrics/ParameterLists @initializer = initializer @condition = condition @step = step @body = body @continue = continuation @label = label end |
Instance Method Details
#run(env, _context) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/peruby/op/loop.rb', line 28 def run(env, _context) env.with_scope do @initializer&.run(env, :void) while @condition.nil? || Conv.truthy?(@condition.run(env, :scalar)) break unless run_iteration?(env) @step&.run(env, :void) end end nil end |