using System;using System.Collections.Generic; namespace Console1{ class Program { static void Main(string[] args) { List animals = new List(); animals.Add("cat"); animals.Add("dog"); animals.Add("fox"); foreach (string animal in animals) { Console.WriteLine(animal); } } }} /* Outputcatdogfox*/ using System;using System.Collections.Generic; namespace Console1{ class Program { static void Main(st..
using System; namespace Console1{ class Program { static void Main(string[] args) { for (int i = 0; i < 4; i++) { Console.WriteLine(i); } } }} /* Output0123*/ using System; namespace Console1{ class Program { static void Main(string[] args) { int[] arr = { 0, 1, 2, 3 }; foreach (int i in arr) { Console.WriteLine(i); } } }} /* Output0123*/
# Python 3 : Generator def infinite_generator(): count = 0 while True: count += 1 yield count gen = infinite_generator()print(type(gen)) # print(next(gen)) # 1print(next(gen)) # 2print(next(gen)) # 3print(next(gen)) # 4 """ Output1234"""
# Python 3 : Generator def my_generator(): yield 1 yield 2 yield 3 for i in my_generator(): print(i) """ Output123""" # Python 3 : Generator def my_generator(): yield 1 yield 2 yield 3 gen = my_generator()print(type(gen)) # for i in gen: print(i) """ Output123""" # Python 3 : Generator def my_generator(): yield 1 yield 2 yield 3 gen = my_generator() print(next(gen)) # 1print(next(gen)) # 2print(..
# Python 3 : Iterator class CountDown: def __init__(self, top: int): self.current = top + 1 def __iter__(self) -> 'CountDown': return self def __next__(self) -> int: self.current -= 1 if self.current < 0: raise StopIteration else: return self.current if __name__ == '__main__': c1 = CountDown(3) print(type(c1)) # for i in c1: print(i) # 3 2 1 0 c2 = CountDown(3) print(next(c2)) # 3 print(next(c2)..