home > 比較編 > Perl, PHP, Python, Ruby > functions >

ForNext

Only Do What Only You Can Do

153. generator

VBScript

JScript

Perl

none











PHP

none











Python

def make_counter():
  i = 0
  while True:
    i += 1
    yield i

nays = make_counter()
print(nays.next())




Ruby

# Ruby 1.9:
def make_counter
  return Fiber.new do
    i = 0
    while true
      i += 1
      Fiber.yield i
    end
  end
end
nays = make_counter
puts nays.resume

PowerShell

Scala

F#

C

C++

C++Builder

VC++

C#

Java

Objective-C

D

VB

VB.NET

Delphi

Ada

PL/SQL

T-SQL

関数型

inserted by FC2 system