Iterator

Iterator
iter

1 C++[편집]

std::vector<int> items;
items.push_back(1); // Append integer value '1' to vector 'items'
items.push_back(2); // Append integer value '2' to vector 'items'
items.push_back(3); // Append integer value '3' to vector 'items'

for (std::vector<int>::iterator i = items.begin(); i != items.end(); ++i) { // Iterate through 'items'
   std::cout << *i; // And print value of 'items' for current index
}
//in C++11
for(auto i:items){
   std::cout << i; // And print value of 'items'
}
// 123

2 C#[편집]

explicit version
IEnumerator<MyType> iter = list.GetEnumerator();
while (iter.MoveNext())
    Console.WriteLine(iter.Current);
implicit version
foreach (MyType value in list)
    Console.WriteLine(value);

3 Java[편집]

Iterator iter = list.iterator();
//Iterator<MyType> iter = list.iterator();    in J2SE 5.0
while (iter.hasNext()) {
    System.out.print(iter.next());
    if (iter.hasNext())
        System.out.print(", ");
}

4 Python[편집]

s = 'abc'
it = iter(s)
print( next(it) ) # a
print( next(it) ) # b
s = 'abc'
it = iter(s)
print( it.__next__() ) # a
print( it.__next__() ) # b

5 같이 보기[편집]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}