Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,330 --> 00:00:06,750
OK, welcome back to the solution that's first of all, to remove this myth that we do not actually
2
00:00:06,750 --> 00:00:07,230
need it.
3
00:00:07,500 --> 00:00:13,590
We used it in one of the previous exercises, but now we don't have any interest in any interest in
4
00:00:13,590 --> 00:00:13,760
it.
5
00:00:14,280 --> 00:00:20,970
So what we have tried to do in this exercise is simply to get some number gets done and then we should
6
00:00:20,970 --> 00:00:28,410
print all the natural numbers from one up to these given numbers.
7
00:00:29,330 --> 00:00:29,790
Right.
8
00:00:29,910 --> 00:00:36,570
And on the next line, to print all the values from up to one.
9
00:00:36,930 --> 00:00:37,390
Right.
10
00:00:37,410 --> 00:00:39,740
Simply printing them vice versa.
11
00:00:39,750 --> 00:00:43,560
So it will be like like that.
12
00:00:43,630 --> 00:00:46,350
OK, so that's our task.
13
00:00:46,350 --> 00:00:49,950
And we are going to do it using loops probably.
14
00:00:49,950 --> 00:00:52,650
Right, because we are in the section of loops.
15
00:00:52,980 --> 00:01:00,600
So let's create a new variable enum and as usual, print Afghans or and and then we are going to read
16
00:01:00,600 --> 00:01:01,710
the variable number.
17
00:01:02,400 --> 00:01:08,970
Let me just take this key word here and are using kind of function to read the number from the user
18
00:01:08,970 --> 00:01:11,120
and story inside variable num.
19
00:01:11,370 --> 00:01:13,560
Basically the first step is complete.
20
00:01:13,920 --> 00:01:19,170
We have the NUM and now let's think about how we should implement and use the loop.
21
00:01:19,860 --> 00:01:26,580
So basically, if we want to use the loop, one good way would be to use probably the for a for loop.
22
00:01:26,580 --> 00:01:26,900
Right.
23
00:01:27,090 --> 00:01:33,990
So if we want to use the for loop let's create additional variable called this variable I and this variable
24
00:01:33,990 --> 00:01:41,160
will be used on every duration in our loop and also is our condition, so forth.
25
00:01:41,820 --> 00:01:48,270
And I think enties not iis equal to zero because we already declared I.
26
00:01:48,300 --> 00:01:51,320
So that's the initial phase of these for loop.
27
00:01:51,330 --> 00:01:52,920
Let's just increase it a little bit.
28
00:01:53,400 --> 00:01:59,730
And the condition is as long as I is less than or equal to num I plus plus.
29
00:01:59,820 --> 00:02:07,140
So the question is if this statement is OK and why am I asking you this question.
30
00:02:07,140 --> 00:02:09,880
Because if I start from zero.
31
00:02:09,960 --> 00:02:15,870
OK, but we want to bring just the natural numbers without the zero then probably it will make sense
32
00:02:15,870 --> 00:02:17,500
to start dying from one.
33
00:02:17,560 --> 00:02:20,610
OK, so from one up to five included.
34
00:02:20,610 --> 00:02:24,140
OK, that's the explanation of this condition.
35
00:02:24,150 --> 00:02:31,710
So for I equals to one as long as I is less than or equal to num c++ on every duration and we are going
36
00:02:31,710 --> 00:02:41,310
to print simply print f what are we going to print the value of I so percentage DB and basically that's
37
00:02:41,310 --> 00:02:42,460
how we are going to do it.
38
00:02:42,480 --> 00:02:46,330
So instead of these percentages we will use AI.
39
00:02:46,920 --> 00:02:47,290
Right.
40
00:02:48,150 --> 00:02:52,330
So let's simply try to build and run this program and see how it works.
41
00:02:53,160 --> 00:02:58,770
So press build and run and hopefully everything is OK.
42
00:02:58,800 --> 00:03:00,330
So let's see what happens here.
43
00:03:00,570 --> 00:03:02,270
So answer now.
44
00:03:02,370 --> 00:03:04,330
Why doesn't enter now.
45
00:03:04,680 --> 00:03:05,840
So let's go with five.
46
00:03:05,850 --> 00:03:07,480
So one, two, three, four, five.
47
00:03:07,650 --> 00:03:08,250
Awesome.
48
00:03:08,280 --> 00:03:11,250
Everything seems to be working correctly so far.
49
00:03:11,520 --> 00:03:13,680
And let's use like a Channel Ten.
50
00:03:14,130 --> 00:03:16,370
So one, two, three, four, five, six, seven, eight, nine, 10.
51
00:03:16,430 --> 00:03:16,880
Awesome.
52
00:03:17,160 --> 00:03:24,630
So that part this part of printing, all the values, all the natural numbers from one up to now seems
53
00:03:24,630 --> 00:03:25,900
to be working correctly.
54
00:03:26,280 --> 00:03:33,420
Now, what do we have to do is print all the values from num up to one, OK, right afterwards and how
55
00:03:33,420 --> 00:03:34,640
should we basically do it?
56
00:03:35,160 --> 00:03:40,320
So also again, there are a couple of options that we can use.
57
00:03:40,320 --> 00:03:42,420
We can use a for loop, we can use a while loop.
58
00:03:42,540 --> 00:03:45,720
There is no problem with using using either of them.
59
00:03:46,020 --> 00:03:48,840
So I'm going to stick with the for loop.
60
00:03:48,840 --> 00:03:55,530
So for I equals to num, that's the first value that I'm going to printing in this loop.
61
00:03:56,220 --> 00:04:04,590
And as long as num I'm going to execute this loop, as long as, not as long as I is greater or equal
62
00:04:04,770 --> 00:04:06,030
to one ok.
63
00:04:06,030 --> 00:04:09,720
Or as long as I is greater than, than zero.
64
00:04:10,680 --> 00:04:16,150
So and what operation are we going to do on each iteration.
65
00:04:16,170 --> 00:04:19,060
So are we going still to go with like eight plus plus.
66
00:04:19,680 --> 00:04:26,340
Probably not because we want to start from five for example, and then to go with for three to one up
67
00:04:26,340 --> 00:04:27,980
until we reach these condition.
68
00:04:29,190 --> 00:04:36,840
So it's probably going to be minus minus, which is basically in discriminating the value of I buy one
69
00:04:36,870 --> 00:04:38,570
on every iteration.
70
00:04:39,540 --> 00:04:40,610
So awesome.
71
00:04:40,830 --> 00:04:43,860
And let's write the body of this loop.
72
00:04:43,860 --> 00:04:48,930
So print F and the same, we will use percentage D again.
73
00:04:49,110 --> 00:04:50,000
Just I.
74
00:04:50,190 --> 00:04:50,620
OK.
75
00:04:51,540 --> 00:04:59,100
So in these for a loop we will print from one to five in these four liberal print from five to one hopefully
76
00:04:59,100 --> 00:04:59,850
if everything works.
77
00:04:59,910 --> 00:05:00,560
Correctly.
78
00:05:01,100 --> 00:05:04,480
And also, let's build and run it and see what happens.
79
00:05:04,510 --> 00:05:09,590
So build and run my computer getting tired today.
80
00:05:09,750 --> 00:05:10,620
What's going on?
81
00:05:10,650 --> 00:05:13,020
So answer no, let's say five.
82
00:05:13,710 --> 00:05:19,050
OK, so here you can see on the screen, one, two, three, four, five and five, four, three, two,
83
00:05:19,050 --> 00:05:19,400
one.
84
00:05:20,280 --> 00:05:22,760
Basically, everything seems to be working correctly.
85
00:05:22,770 --> 00:05:30,740
The only thing that we should add is just to you know, we should separate between the lines.
86
00:05:30,750 --> 00:05:36,360
So on the first line, we should point from one to five and on the next line we should print from five
87
00:05:36,360 --> 00:05:36,890
to one.
88
00:05:37,380 --> 00:05:46,350
So for that, we will simply add and print half of backslash and at the end of each of these four bluebook.
89
00:05:47,690 --> 00:05:54,830
And it's kind of interesting question, why didn't we add a backslash and right here, so simple solution,
90
00:05:54,830 --> 00:05:59,610
would it be that you don't want to print all the values one after another in use here?
91
00:05:59,630 --> 00:06:08,600
I don't know a lot of rows, because if we would have used it this way, that in this case, it will
92
00:06:08,600 --> 00:06:14,210
mean that on every iteration we will use a new line and we will not print one, two, three, four or
93
00:06:14,210 --> 00:06:15,680
five on just one line.
94
00:06:15,920 --> 00:06:21,170
But rather we would print one new line to new line three, new line four and so on.
95
00:06:22,010 --> 00:06:29,240
So we only want to print a new line after we are done printing all the values from one to number and
96
00:06:29,240 --> 00:06:35,480
also the same just for simplicity we will add after the second four for Loop.
97
00:06:36,290 --> 00:06:38,510
And yeah, I think we are good.
98
00:06:39,700 --> 00:06:41,980
We've done a pretty good job.
99
00:06:42,010 --> 00:06:45,520
Let's just check it out if it works exactly as we expected.
100
00:06:47,050 --> 00:06:48,950
Simply let's remove these for a loop.
101
00:06:48,970 --> 00:06:50,500
OK, so let's remove it.
102
00:06:51,620 --> 00:06:59,980
Let's remove the for loop and what we will say and let's make it as an example.
103
00:07:00,310 --> 00:07:05,380
Let's create a temp variable just to store the value of a copy of the value.
104
00:07:05,710 --> 00:07:16,870
So we'll say while no, there is no reason for using temp just here, so we will say I equals to one
105
00:07:16,870 --> 00:07:21,520
initialize it and we will say as long as I use less than or equal to.
106
00:07:22,600 --> 00:07:24,410
And in this case, we will print.
107
00:07:25,330 --> 00:07:32,530
OK, so we initialize I and given we give it some value, some initialize value I equals to one.
108
00:07:32,530 --> 00:07:35,780
As long as I is less than num we will print time.
109
00:07:35,800 --> 00:07:41,230
So let's just make sure that it basically prints the one of the same solution as previously.
110
00:07:41,240 --> 00:07:43,150
So enter num seven.
111
00:07:43,560 --> 00:07:45,890
Oh we got a problem.
112
00:07:45,970 --> 00:07:47,340
So what's the problem guys.
113
00:07:47,860 --> 00:07:48,790
Take a second.
114
00:07:48,790 --> 00:07:49,680
Think about it.
115
00:07:50,110 --> 00:07:52,900
Why do we have an endless loop here.
116
00:07:53,530 --> 00:08:01,780
So the answer is very simple because we print I as long as I's list the num ok and if nomy seven and
117
00:08:01,780 --> 00:08:09,460
I's one then the slope is going to be infinite because I is not incremented by any number.
118
00:08:09,520 --> 00:08:13,420
So what you can do about it is simply use plus plus.
119
00:08:14,020 --> 00:08:22,210
OK, and that's on every duration I is going to be implemented by one and basically that's how you avoid
120
00:08:23,170 --> 00:08:24,430
these endless loop.
121
00:08:24,440 --> 00:08:31,640
So let's check it out once again, build and run it and let's see what's going on to be executed now.
122
00:08:31,660 --> 00:08:32,410
Six, seven.
123
00:08:32,440 --> 00:08:36,990
So one, two, three, four, five, six, seven, seven, six, five, four, three, two, one.
124
00:08:37,480 --> 00:08:38,720
And there you go.
125
00:08:38,740 --> 00:08:43,270
So basically, once again, we used a while loop in the for a loop.
126
00:08:43,270 --> 00:08:50,530
And I've shown you you've you've seen how you can use it either while loop or for a loop, whatever
127
00:08:50,530 --> 00:08:52,660
you like, whatever you prefer in this option.
128
00:08:52,960 --> 00:08:54,550
Of course this I can be.
129
00:08:55,210 --> 00:08:56,650
These I can be.
130
00:08:56,930 --> 00:08:57,610
Where is it.
131
00:08:58,580 --> 00:09:06,530
Lisa, I can be also removed and you can just use it in one line so it will print the value of it and
132
00:09:06,530 --> 00:09:09,680
right afterward it will increment the variable.
133
00:09:09,680 --> 00:09:15,800
I buy one after printing results just to show you that you will be 100 percent sure.
134
00:09:16,160 --> 00:09:17,600
That is exactly how it works.
135
00:09:17,960 --> 00:09:18,680
There you go.
136
00:09:18,710 --> 00:09:22,760
The same results and yeah, feel free to use whatever you like.
137
00:09:22,790 --> 00:09:24,200
The while loop for a loop.
138
00:09:24,590 --> 00:09:27,090
And basically this is it for these video guys.
139
00:09:27,440 --> 00:09:30,010
My name is Vlad Vlad Netsky actually.
140
00:09:30,020 --> 00:09:31,820
And yeah.
141
00:09:31,850 --> 00:09:38,660
And this is Alphatech Academy and feel free to ask any questions and of course leave some feedback,
142
00:09:38,660 --> 00:09:44,560
some review so that this way I will know if you like the material so far or not.
143
00:09:44,990 --> 00:09:48,560
And until next time, have a great day and I'll see you then.
144
00:09:48,770 --> 00:09:49,190
Bye.
13166
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.