1 00:00:00,630 --> 00:00:01,720 Hello and welcome. 2 00:00:01,740 --> 00:00:10,740 In this lecture I'm going to explain how the for loop works in the Ruby programming language. 3 00:00:11,460 --> 00:00:16,440 What does a four loop do for a loop. 4 00:00:16,440 --> 00:00:25,820 Basically it is use when the number of iterations is known before it enters the loop. 5 00:00:25,830 --> 00:00:36,770 What that means is that the present value of a for loop is the value iterated over on less. 6 00:00:36,870 --> 00:00:43,550 A break is you some time with any form should be put in a loop you can use a break to break the loop. 7 00:00:43,560 --> 00:00:46,480 So what this is saying is there's no break. 8 00:00:46,560 --> 00:00:48,750 There is someone family for the four look. 9 00:00:48,960 --> 00:00:51,980 Is in value iterated over. 10 00:00:52,380 --> 00:00:55,540 So we're going to see how that works. 11 00:00:55,680 --> 00:01:05,280 Also a for loop is like it will happen that you don't have to use the to do option is optional you don't 12 00:01:05,280 --> 00:01:13,440 need to use the key word for looks is rarely use in modern Ruby programs. 13 00:01:13,800 --> 00:01:15,180 So let's look at. 14 00:01:15,180 --> 00:01:17,530 He'd be a syntax. 15 00:01:17,650 --> 00:01:26,370 So we've got a 4 key word followed by airable which could be Hillary and then you won't be on clits 16 00:01:26,490 --> 00:01:28,450 in the hurry. 17 00:01:28,530 --> 00:01:31,860 The for loop will iterate. 18 00:01:31,860 --> 00:01:39,120 True and that based on the expression you set it to execute what I could. 19 00:01:39,340 --> 00:01:43,410 In that block and then the statement ends. 20 00:01:43,590 --> 00:01:45,320 So let's see how that works. 21 00:01:45,590 --> 00:01:52,000 I have got my interactive Ruby first and I want to do is define an array. 22 00:01:52,090 --> 00:01:56,170 I'll say Hey Jake was too. 23 00:01:56,940 --> 00:02:02,340 I've seen one to three. 24 00:02:04,280 --> 00:02:12,030 Four five six seven. 25 00:02:12,290 --> 00:02:13,690 Are close. 26 00:02:13,940 --> 00:02:16,770 Mary and the arrow is now closed. 27 00:02:16,790 --> 00:02:20,910 We've got a very there or seven up. 28 00:02:21,410 --> 00:02:25,660 So I'm going to use a for loop to iterate. 29 00:02:25,820 --> 00:02:26,630 True. 30 00:02:28,190 --> 00:02:37,120 Remember a for loop basically knows what he's going to eat right before he goes into the loop. 31 00:02:37,220 --> 00:02:45,880 So one time went up and went to see x 4 to define a for loop for X.. 32 00:02:47,330 --> 00:02:50,620 In that. 33 00:02:51,110 --> 00:02:53,320 We know the area has got seven outlets. 34 00:02:53,330 --> 00:02:56,660 I'm just going to list all of them. 35 00:02:56,790 --> 00:03:04,630 Here's two three four five three. 36 00:03:09,950 --> 00:03:12,180 Seven. 37 00:03:12,480 --> 00:03:22,140 So we've got all the members on that Arey that the value that X is going to loop through then here is 38 00:03:22,140 --> 00:03:25,510 where we'll put the statement they could. 39 00:03:25,500 --> 00:03:27,530 They're all executed. 40 00:03:27,910 --> 00:03:30,940 So what I want I want it to. 41 00:03:31,560 --> 00:03:35,360 I just wanted to add put the value of that x. 42 00:03:35,370 --> 00:03:46,110 So how it goes to the Aries I want it to list the objects in that hurry so I just see it if I press 43 00:03:46,230 --> 00:03:52,320 end now and press enter it should list all the members of that Hurry. 44 00:03:52,410 --> 00:03:56,660 As you can see it's listed all of them so there's busiek we. 45 00:03:56,700 --> 00:03:59,180 How a fawn Look works. 46 00:03:59,370 --> 00:04:00,690 Thanks for watching. 47 00:04:00,690 --> 00:04:01,510 Bye for now.