1 00:00:00,460 --> 00:00:04,290 Another kind of iterator in Ruby that works specifically with 2 00:00:04,290 --> 00:00:06,410 integers is the times iterator. 3 00:00:07,420 --> 00:00:10,050 The times iterator will take a number, 4 00:00:10,050 --> 00:00:14,650 execute the statements in the block that number of times. 5 00:00:14,650 --> 00:00:16,630 The times iterator, optionally, 6 00:00:16,630 --> 00:00:21,380 takes an argument, and, just like array indexes, starts at zero. 7 00:00:22,430 --> 00:00:25,620 Let's see how that works now using WorkSpaces. 8 00:00:25,620 --> 00:00:29,880 Okay, using a Ruby workspace let's go ahead and create a new file. 9 00:00:29,880 --> 00:00:31,430 We'll call this times.rb. 10 00:00:31,430 --> 00:00:36,890 The times method is really easy to use. 11 00:00:36,890 --> 00:00:40,982 We'll take any number, let's use 5 as an example and 12 00:00:40,982 --> 00:00:46,770 use a dot like we're going to call a method and then we use the word times. 13 00:00:48,330 --> 00:00:51,050 From there, we write a do end block like we're used to. 14 00:00:52,170 --> 00:00:56,430 Now let's just type puts hello. 15 00:00:57,820 --> 00:01:02,460 Now we can run this, using ruby times.rb. 16 00:01:02,460 --> 00:01:05,359 And we see that it prints hello five times. 17 00:01:10,042 --> 00:01:13,670 And we can also send arguments into the times method. 18 00:01:16,780 --> 00:01:18,340 Let's create a new file. 19 00:01:18,340 --> 00:01:24,830 To test that out, we'll call it times_with_argument.rb. 20 00:01:24,830 --> 00:01:28,110 And we'll write that just like we did the times loop. 21 00:01:29,967 --> 00:01:31,525 So here we did five times. 22 00:01:34,256 --> 00:01:37,980 Do end. 23 00:01:37,980 --> 00:01:40,310 Now just like with other iterators and blocks, 24 00:01:40,310 --> 00:01:45,490 if we want to send an argument to the block we do so by writing a pipe and 25 00:01:45,490 --> 00:01:49,650 putting the local variable inside of the pipes. 26 00:01:50,840 --> 00:01:54,580 The times method can take one argument into the block 27 00:01:56,550 --> 00:01:58,280 and we'll go ahead and print that out. 28 00:02:02,470 --> 00:02:06,858 And if we run ruby times_with_argument.rb. 29 00:02:06,858 --> 00:02:11,724 We can see, we get all of these different arguments as the item and 30 00:02:11,724 --> 00:02:15,100 it starts with zero just like array indexes. 31 00:02:16,160 --> 00:02:20,230 Try practicing with the times iterator on your own now, using WorkSpaces.