Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,430 --> 00:00:01,990
So what is going on, guys?
2
00:00:02,020 --> 00:00:07,900
And welcome back to another amazing exercise in our programming course.
3
00:00:08,710 --> 00:00:13,930
And this exercise, as I said previously, is not so easy.
4
00:00:14,260 --> 00:00:17,540
But I think we will be good, pretty good with that.
5
00:00:18,200 --> 00:00:26,650
So once again, we what we want to do in this exercise is to find if a given sequence is very ascending
6
00:00:26,650 --> 00:00:28,740
or not very ascending.
7
00:00:29,170 --> 00:00:35,820
And we talked about what is the meaning of these terminology, very ascending and not very ascending.
8
00:00:36,700 --> 00:00:38,410
So just a quick reminder.
9
00:00:38,420 --> 00:00:46,270
We said previously that we are going to receive a sequence amount of numbers that we do not know in
10
00:00:46,270 --> 00:00:48,550
advance how many numbers we will have.
11
00:00:49,120 --> 00:00:54,280
OK, so we will get, for example, five, seven, 10 or whatever numbers.
12
00:00:54,880 --> 00:01:00,640
And based on these numbers, once we get them, we get them in some sort of order.
13
00:01:00,700 --> 00:01:01,000
Right.
14
00:01:01,000 --> 00:01:07,060
So we get the first number, then we get the second number and the fifth, the third, the fourth and
15
00:01:07,060 --> 00:01:07,530
so on.
16
00:01:07,960 --> 00:01:16,840
And I want to know a simple question is this sequence is very ascending or not basically taking any
17
00:01:16,840 --> 00:01:23,920
value and asking the following question, will the next value be greater than the previous?
18
00:01:24,160 --> 00:01:29,950
If the question is yes for all of the sequence, then we should simply print various sending.
19
00:01:30,310 --> 00:01:33,950
Otherwise we should print not very ascending.
20
00:01:34,300 --> 00:01:41,320
So now that the instructions are clarified, once again, let's dive into coding.
21
00:01:42,100 --> 00:01:48,190
And what I wanted to start in this exercise is, first of all, understand the following concept, because
22
00:01:48,190 --> 00:01:55,720
a lot of students having a hard time with this kind of exercise and kind of approach when you don't
23
00:01:55,720 --> 00:02:01,180
know in advance how many values your program is going to read from the user.
24
00:02:01,990 --> 00:02:08,920
So one approach is to use arrays, but in this case, we didn't study arrays yet.
25
00:02:09,580 --> 00:02:15,620
So how can we know in advance how many variables we should create to hold these values?
26
00:02:15,640 --> 00:02:22,180
So, for example, we have the following sequence like one five and six, let's say.
27
00:02:22,600 --> 00:02:27,990
Then how can we know in advance that we need to create, let's say, three variables?
28
00:02:28,000 --> 00:02:31,180
And do we actually need to create three variables?
29
00:02:32,020 --> 00:02:35,200
And what will be the case if the sequence goes like this?
30
00:02:35,320 --> 00:02:40,870
So three, five, eight and then one and then, I don't know, 10 and so on.
31
00:02:41,230 --> 00:02:44,070
So will we need to create five variables?
32
00:02:44,080 --> 00:02:46,810
Basically, how can we control this part?
33
00:02:47,380 --> 00:02:49,170
And the answer is very simple.
34
00:02:49,260 --> 00:02:57,330
OK, that's actually the main, let's say, trick in this exercise, and it says the following thing.
35
00:02:58,360 --> 00:03:01,580
So you don't need to know all the sequence.
36
00:03:01,600 --> 00:03:03,080
It doesn't interest you.
37
00:03:03,730 --> 00:03:10,390
The main thing that you need to know and the main thing that you need to work with is basically just
38
00:03:10,390 --> 00:03:16,120
to American values at a time so you don't need these values of three.
39
00:03:16,150 --> 00:03:20,550
He does not need to know what will be the fourth value afterwards.
40
00:03:21,100 --> 00:03:27,520
It simply needs to know that the condition between its neighbor, its first neighbor, its neighbor
41
00:03:27,520 --> 00:03:29,490
and the right will be satisfied.
42
00:03:30,040 --> 00:03:37,000
So as long as we know that, for example, we got the first value and then the next value, we we want
43
00:03:37,000 --> 00:03:40,210
to know is if the neighbor is greater than me.
44
00:03:40,430 --> 00:03:44,680
If so, then OK, maybe it's still very ascending.
45
00:03:44,860 --> 00:03:46,190
And if not, OK.
46
00:03:46,330 --> 00:03:47,700
So that's for sure.
47
00:03:47,710 --> 00:03:52,000
Not very ascending, but that's how we are going to work.
48
00:03:52,000 --> 00:03:55,980
We are going simply to check two values at a time.
49
00:03:56,020 --> 00:04:03,010
Let's say the current value will be five and the previous value will be three, and then the current
50
00:04:03,010 --> 00:04:06,370
value will be eight and the previous value will be five.
51
00:04:06,370 --> 00:04:14,140
So the left value, the value on the left will be of the previous value and the current value will be
52
00:04:14,140 --> 00:04:15,490
the value on the right.
53
00:04:15,730 --> 00:04:20,450
And we are simply going to compare them in kind of pairs.
54
00:04:20,500 --> 00:04:25,540
OK, and based on the result of the condition, we are going to make some conclusions.
55
00:04:25,630 --> 00:04:26,170
All right.
56
00:04:27,070 --> 00:04:34,060
So I hope you guys are with me so far because this exercise once again is not so trivial and it requires
57
00:04:34,060 --> 00:04:40,450
your attention and your concentration to get it done correctly and right.
58
00:04:41,260 --> 00:04:45,310
So let us start looking at this code.
59
00:04:45,430 --> 00:04:47,680
So we have here is line eleven.
60
00:04:47,680 --> 00:04:55,690
We have in sequence size and these value, this variable will simply represent the size of the sequence.
61
00:04:55,880 --> 00:04:57,970
So in this case, the size is three.
62
00:04:57,970 --> 00:04:59,710
In this case, the size is five.
63
00:05:00,040 --> 00:05:08,070
So we just read this value from the user in advance and where we are doing that simply in these lines,
64
00:05:08,380 --> 00:05:14,350
so printf insert size, which is the total size of the sequence, and read the value and store it inside
65
00:05:14,350 --> 00:05:16,120
of the sequence size variable.
66
00:05:17,210 --> 00:05:25,130
Also, what we have is these two variables, previous value and current value, which will simply represent,
67
00:05:25,130 --> 00:05:30,650
as they just said every time, the value, let's say, on the left and the value on the right.
68
00:05:30,830 --> 00:05:38,270
OK, so we will assume and we will nullify them and we will assume that these are given sequence consists
69
00:05:38,270 --> 00:05:41,620
only of negative only of positive values.
70
00:05:42,110 --> 00:05:48,680
And if we wanted to like to support also negative values, then a little bit of modifications should
71
00:05:48,680 --> 00:05:49,160
be done.
72
00:05:49,550 --> 00:05:58,220
But for the sake of simplicity of this exercise, we will assume that our sequence contains only positive
73
00:05:58,220 --> 00:05:58,850
numbers.
74
00:05:59,750 --> 00:06:00,440
All right.
75
00:06:00,680 --> 00:06:07,000
So now that we know these match, let's also create some flag.
76
00:06:07,240 --> 00:06:14,120
OK, then it will be a simple variable that will contain either one or zero.
77
00:06:14,240 --> 00:06:15,410
OK, nothing special.
78
00:06:16,310 --> 00:06:26,060
And this flag will simply let us know if we if we have a sequence of that is very ascending or not.
79
00:06:26,420 --> 00:06:29,080
So basically, what do I mean by that?
80
00:06:29,570 --> 00:06:32,220
I mean, let's assume awesome.
81
00:06:32,750 --> 00:06:38,410
So now that we know this match, let's proceed with line 12 with line 20.
82
00:06:38,960 --> 00:06:41,240
So we are asking you the following question.
83
00:06:41,240 --> 00:06:47,330
If sequence size is less than or equal to zero, that's just a condition that I want to check and make
84
00:06:47,330 --> 00:06:51,070
sure that the sequence has at least one value.
85
00:06:51,110 --> 00:06:58,250
Otherwise, we should bring some don't message to the screen and which says, wait a minute, try again,
86
00:06:58,250 --> 00:06:58,730
please.
87
00:06:58,760 --> 00:07:01,400
OK, because that does not make sense of the sequence.
88
00:07:01,400 --> 00:07:03,500
Size is less than or equal to zero.
89
00:07:03,530 --> 00:07:06,240
There is no sequence right there.
90
00:07:06,560 --> 00:07:13,010
In this case, we will simply print some error message and also some option is simply to exit the program
91
00:07:13,010 --> 00:07:22,050
or like to run a loop that will read the sequences over and over again until we insert some good sequences.
92
00:07:22,070 --> 00:07:23,360
That's also an option.
93
00:07:23,360 --> 00:07:24,350
Some do while.
94
00:07:24,740 --> 00:07:26,660
OK, so no problem with that.
95
00:07:26,660 --> 00:07:29,180
Maybe Will will also cover it up here.
96
00:07:29,990 --> 00:07:30,530
All right.
97
00:07:30,540 --> 00:07:32,200
So that's OK.
98
00:07:32,720 --> 00:07:39,030
So the LS is actually the main logic of the main core of this program, of this exercise.
99
00:07:39,470 --> 00:07:46,100
So what we are going to do, we are going, of course, to use a while loop or better say it, do while
100
00:07:46,100 --> 00:07:46,460
loop.
101
00:07:47,300 --> 00:07:50,740
And what we are going to do is basically come here.
102
00:07:50,780 --> 00:08:00,530
We can see that this is to do do this section, do this kind of block, these block of commands while
103
00:08:00,530 --> 00:08:05,560
the condition is greater, this condition of sequences is greater than zero.
104
00:08:06,230 --> 00:08:10,040
And what's the difference basically between a while and do while?
105
00:08:10,490 --> 00:08:17,570
So a while simply says that even the first iteration of the while loop the condition should be checked.
106
00:08:18,360 --> 00:08:26,060
But here we assume that we can do it also with this, because we checked the sequence sizes not less
107
00:08:26,060 --> 00:08:27,300
than or equal to zero.
108
00:08:27,680 --> 00:08:33,770
So in this case, we can start with doing this body once again.
109
00:08:34,190 --> 00:08:41,420
But again, there is no actual reason why we could not have used even while here just instead of the
110
00:08:41,420 --> 00:08:41,840
while.
111
00:08:41,840 --> 00:08:43,070
I don't see it.
112
00:08:43,820 --> 00:08:51,380
Maybe I'm mistaken because I'm a little bit tired right now, but that was my solution, so I'm OK.
113
00:08:51,400 --> 00:08:54,320
So anyway, let's get back to business.
114
00:08:54,350 --> 00:08:55,840
So that's the loop body.
115
00:08:55,850 --> 00:08:59,260
OK, from line twenty six up to line thirty eight.
116
00:08:59,270 --> 00:09:06,080
That's the little body in what we are going to do inside of this loop body is simply to read the values
117
00:09:06,080 --> 00:09:07,550
from the user a one by one.
118
00:09:07,920 --> 00:09:14,690
OK, so print f insert value and we are going to read the current value and store it.
119
00:09:15,080 --> 00:09:20,690
OK, so we read for example if we have this sequence, let's copy that.
120
00:09:21,140 --> 00:09:22,160
Let's come here.
121
00:09:22,740 --> 00:09:27,830
OK, so that's the sequence that the first sequence and let's also copy the second sequence.
122
00:09:28,580 --> 00:09:31,680
So these are just the two sequences that we have.
123
00:09:32,270 --> 00:09:35,970
So what we are doing is, first of all, current value equals to one.
124
00:09:35,990 --> 00:09:43,220
OK, so we are asking if current value is less than zero, then we can print some nice message.
125
00:09:43,220 --> 00:09:46,610
No is not positive and that's it otherwise.
126
00:09:46,900 --> 00:09:50,300
OK, because we don't want to to deal with this case.
127
00:09:50,630 --> 00:09:56,600
Otherwise we will simply use these these body of the LS.
128
00:09:56,990 --> 00:10:02,500
But let me just mark this place because I want us to come back to here later on.
129
00:10:02,510 --> 00:10:04,070
So come back here.
130
00:10:06,480 --> 00:10:07,340
OK.
131
00:10:08,560 --> 00:10:15,310
And now let's talk about the Elsberry, so if the current value is less than or is less than or equal
132
00:10:15,370 --> 00:10:24,040
to the previous value, which is not OK, which simply specifies we are not working with a very ascending
133
00:10:24,370 --> 00:10:27,800
sequence, not very ascending.
134
00:10:28,480 --> 00:10:35,230
So if that's the case, if we do not work with a very ascending, then we will simply turn off these
135
00:10:35,230 --> 00:10:37,630
very ascending fact to be equal to zero.
136
00:10:38,290 --> 00:10:46,360
So from this point on, the very ascending flag can never return to be one, because that does not make
137
00:10:46,360 --> 00:10:47,190
any sense.
138
00:10:47,200 --> 00:10:53,020
If we found out that the current value is less than or equal to the previous value.
139
00:10:53,350 --> 00:11:01,420
And the result of this condition simply means that this sequence is not very ascending, then definitely
140
00:11:01,420 --> 00:11:05,440
we will keep this flag as is equal to zero.
141
00:11:06,250 --> 00:11:06,820
Awesome.
142
00:11:07,150 --> 00:11:16,180
So then later on we will simply copy the previous value and simply copy the current value into the previous
143
00:11:16,180 --> 00:11:16,730
value.
144
00:11:16,750 --> 00:11:21,730
So we said that the previous value is always on the left of the current value is always on the right.
145
00:11:22,000 --> 00:11:28,900
And for the first value that we read here, for the current value, we simply compare it here with the
146
00:11:28,900 --> 00:11:34,780
previous value that equals to zero, which was just some assumption that all the values are going to
147
00:11:34,780 --> 00:11:35,400
be positive.
148
00:11:35,680 --> 00:11:38,310
So let's simply start with the value of zero.
149
00:11:39,280 --> 00:11:45,940
And then of course, at the end of these L's condition, we are going to use sequence size minus minus
150
00:11:45,940 --> 00:11:52,450
just to reduce the sequences by one, because we know that if we have a sequence of five elements and
151
00:11:52,450 --> 00:11:59,590
we read just one element, then only a sequence of four elements is left, then three to one.
152
00:11:59,590 --> 00:12:00,620
And that's it.
153
00:12:01,330 --> 00:12:02,150
So awesome.
154
00:12:02,170 --> 00:12:03,870
So that was the first iteration.
155
00:12:03,880 --> 00:12:10,690
Then you come back again to the second iteration and you know that currently the previous value is one.
156
00:12:10,690 --> 00:12:13,980
And the current value that you are going to read is five.
157
00:12:14,200 --> 00:12:18,050
You are going to check these conditions and to do the following things.
158
00:12:18,050 --> 00:12:21,070
So previous value will be now five and then six.
159
00:12:21,760 --> 00:12:27,760
But in the other sequence example, it will be five and eight and yada, yada, yada.
160
00:12:28,540 --> 00:12:31,220
So basically you've got the idea of how it works.
161
00:12:31,660 --> 00:12:39,640
So here we will come to a point when we are going to have the previous value is eight and the current
162
00:12:39,640 --> 00:12:40,480
value is one.
163
00:12:40,930 --> 00:12:46,610
And this condition is going to be not to be satisfied, is going to be satisfied, actually.
164
00:12:46,960 --> 00:12:50,380
So the current value is less than or equal to previous value.
165
00:12:50,390 --> 00:12:52,210
So one is less than eight.
166
00:12:52,960 --> 00:12:59,140
And that simply indicates that the sequence is not very ascending, that it's not growing up from left
167
00:12:59,140 --> 00:12:59,670
to right.
168
00:13:00,130 --> 00:13:05,320
So that's why we are going to set these flag to be equals to to be equal to zero.
169
00:13:06,270 --> 00:13:13,470
And yeah, that's basically what we are going to do and once we are done, OK, once we are done with
170
00:13:13,470 --> 00:13:21,360
this do while loop, we know what interests us the most is not what were the values of the current value
171
00:13:21,360 --> 00:13:24,870
and previous value, because we lost most of them in the process.
172
00:13:24,870 --> 00:13:25,160
Right.
173
00:13:25,170 --> 00:13:30,320
We only left we are only left with the last two values.
174
00:13:30,330 --> 00:13:36,420
So these value in this value in this case and this value the previous value of this and the current
175
00:13:36,420 --> 00:13:36,770
value.
176
00:13:37,080 --> 00:13:40,650
So we lose a lot of values and we don't actually care about them.
177
00:13:41,100 --> 00:13:44,650
What we do here is about these various sending flag.
178
00:13:45,270 --> 00:13:52,830
So if various sending five equals equals to one, which means our assumption in the beginning that the
179
00:13:52,830 --> 00:13:56,970
sequence is very ascending or that it will be very ascending.
180
00:13:57,270 --> 00:14:02,370
If it was correct, OK, then it equals to one then we can print.
181
00:14:02,370 --> 00:14:04,470
This sequence is very ascending.
182
00:14:04,890 --> 00:14:12,870
Otherwise, if this flag is not one, which means it was zero and if it was zero, then it means that
183
00:14:12,870 --> 00:14:19,830
the sequence is not very ascending because this condition happened then in this case, we will print
184
00:14:19,830 --> 00:14:21,030
the following message.
185
00:14:21,030 --> 00:14:26,250
This sequence is not very ascending, which is kind of great.
186
00:14:27,360 --> 00:14:31,350
Basically, we covered the main part of this exercise so far.
187
00:14:31,710 --> 00:14:35,100
So let's just build and run it and see what happens.
188
00:14:35,100 --> 00:14:36,030
Guys, what do you say?
189
00:14:36,070 --> 00:14:39,990
So insert size the size of the sequence, let's say three.
190
00:14:40,740 --> 00:14:47,330
And if we have three values like one, five and nine, then we are going to get a nice message.
191
00:14:47,340 --> 00:14:53,440
This sequence is very ascending, but if we will try to build and run it, let's say with Valley five
192
00:14:53,460 --> 00:14:58,260
valleys and we'll have one, three, five, four and let's say nine.
193
00:14:58,420 --> 00:15:04,710
OK, so we can see that this sequence is definitely not very ascending because we have the previous
194
00:15:04,710 --> 00:15:09,330
value of five and the current value of four, which is four.
195
00:15:09,330 --> 00:15:11,180
Four is not greater than five.
196
00:15:11,220 --> 00:15:17,100
Then in this case we should get a message of this sequence is not very ascending.
197
00:15:18,440 --> 00:15:19,290
All right.
198
00:15:19,290 --> 00:15:21,390
So I guess this is it.
199
00:15:21,390 --> 00:15:22,890
This is clear to you guys.
200
00:15:22,890 --> 00:15:26,040
If you still if you have any questions, feel free to ask them.
201
00:15:26,380 --> 00:15:26,850
All right.
202
00:15:26,850 --> 00:15:28,170
But I'm not finished yet.
203
00:15:28,170 --> 00:15:34,600
I want simply to optimize this exercise a little bit because let's try to build it and run it once again.
204
00:15:34,780 --> 00:15:36,720
Now, let's take a look at what happens here.
205
00:15:36,720 --> 00:15:44,030
If we insert the value of, I don't know, of minus three, there was just some mistake and we inserted
206
00:15:44,060 --> 00:15:44,690
the size.
207
00:15:45,090 --> 00:15:46,140
So wait a minute.
208
00:15:46,140 --> 00:15:47,160
Try again, please.
209
00:15:47,370 --> 00:15:47,940
All right.
210
00:15:47,940 --> 00:15:53,490
So that's not an option, optimal solution because the program has ended and closed.
211
00:15:53,850 --> 00:15:59,190
And what I want to do is simply to try to to bring this message to the screen.
212
00:15:59,190 --> 00:16:08,480
As long as the user has not inserted the the correct value, which is at least greater than zero.
213
00:16:09,090 --> 00:16:10,680
So what do you think we should do?
214
00:16:11,400 --> 00:16:17,490
Basically, my suggestion is to use do while loop, so let's do something like that.
215
00:16:17,520 --> 00:16:20,760
So first of all, let's try to use just while loop, OK?
216
00:16:20,780 --> 00:16:30,240
So while let's say sequence size is less than or equal to zero, while this condition is satisfied,
217
00:16:30,630 --> 00:16:32,610
let's print the following message.
218
00:16:32,940 --> 00:16:41,010
Let's pray and print F and also scan F and let's read it here.
219
00:16:41,100 --> 00:16:48,710
OK, so as long as it's not equal to this, while it's simply print also this message.
220
00:16:49,890 --> 00:16:51,690
Wait a minute, try again please.
221
00:16:51,960 --> 00:16:54,500
And then insert size total sequence.
222
00:16:54,510 --> 00:16:59,060
OK, so that simply looks OK just by using the while loop.
223
00:16:59,340 --> 00:17:05,770
But the problem is that the sequence size is not initialized and we already check its value against
224
00:17:05,800 --> 00:17:08,750
if it's equal or less than zero.
225
00:17:09,420 --> 00:17:11,160
So that will be a problem.
226
00:17:11,610 --> 00:17:17,910
And what we need to do is simply to optimize this loop to be satisfied that the first iteration will
227
00:17:17,910 --> 00:17:18,960
be executed.
228
00:17:19,860 --> 00:17:27,220
Doesn't matter if we have like like a sequence size is initialized or not.
229
00:17:27,720 --> 00:17:34,020
So how it will look like basically basically let's just remove this line.
230
00:17:34,030 --> 00:17:35,430
We don't actually need it.
231
00:17:36,000 --> 00:17:39,840
So we will do do we will use do while loop.
232
00:17:39,840 --> 00:17:41,250
So do this.
233
00:17:41,530 --> 00:17:46,430
OK, as long as sequence size is less than or equal to zero.
234
00:17:46,470 --> 00:17:55,020
OK, so total size of the sequence let's say greater than zero.
235
00:17:55,800 --> 00:17:58,670
All right, so now let's build and run it.
236
00:17:58,770 --> 00:17:59,940
So let's build and run.
237
00:17:59,940 --> 00:18:01,890
It was the problem on the ls here.
238
00:18:01,890 --> 00:18:04,470
The ELSS unnecessary of course.
239
00:18:04,740 --> 00:18:05,520
So it's just.
240
00:18:05,970 --> 00:18:16,440
That and simply a and it is it should be and let's build and run it, so insert the size of the sequence,
241
00:18:16,440 --> 00:18:18,120
which should be greater than zero.
242
00:18:18,130 --> 00:18:24,990
Let's say we said zero, it says is insert the size again, minus five instead of the size again, minus
243
00:18:24,990 --> 00:18:27,920
three in sort of the size again.
244
00:18:27,930 --> 00:18:30,080
OK, so you get a point.
245
00:18:30,090 --> 00:18:40,380
It will ask us to insert the size of the sequence as long as we we haven't provided a normal size.
246
00:18:40,380 --> 00:18:40,620
Right.
247
00:18:40,620 --> 00:18:41,840
For example, five.
248
00:18:42,360 --> 00:18:48,600
And then once we applied five then we can insert all the values.
249
00:18:49,440 --> 00:18:50,010
Awesome.
250
00:18:50,010 --> 00:18:51,930
So that's awesome guys.
251
00:18:51,930 --> 00:18:55,170
I think we covered a lot in this video.
252
00:18:56,040 --> 00:18:58,920
Just last question for for that.
253
00:18:59,100 --> 00:19:02,130
Since we are already using do while loops and so on.
254
00:19:02,130 --> 00:19:06,620
And you've got the idea of how it can be used here to insert the correct value.
255
00:19:07,480 --> 00:19:09,630
So I want you to take a look at these lines.
256
00:19:09,630 --> 00:19:13,130
OK, it's line twenty five up to line twenty nine.
257
00:19:13,680 --> 00:19:16,770
And we said, let's come back here later.
258
00:19:16,770 --> 00:19:17,090
Right.
259
00:19:17,490 --> 00:19:25,250
So we are coming back and what I want you to, to see here and take a look what is the problem here.
260
00:19:25,350 --> 00:19:32,340
So let's say that we will do the following thing, so let's build and run it.
261
00:19:32,340 --> 00:19:38,970
So this it will be of size, let's say three and the values are going to be like that one minus one
262
00:19:39,510 --> 00:19:40,140
and two.
263
00:19:40,730 --> 00:19:43,350
OK, and let's say three, for example.
264
00:19:43,350 --> 00:19:45,000
I don't know what you're getting.
265
00:19:45,300 --> 00:19:47,280
It's getting kind of problematic.
266
00:19:48,300 --> 00:19:54,750
So the sequence is very ascending, although we inserted a value of minus one, we just got some printed
267
00:19:54,750 --> 00:19:59,280
number is not positive, particularly a lot of things have gone wrong here.
268
00:19:59,730 --> 00:20:06,750
So my suggestion is to use the similar a similar approach to what we've done here with the with the
269
00:20:06,750 --> 00:20:15,240
do, while as long as the current value we are inserting, the user is inserting is is not greater or
270
00:20:15,240 --> 00:20:16,440
equals zero.
271
00:20:16,440 --> 00:20:19,860
So let's do the following inside of these.
272
00:20:19,860 --> 00:20:26,850
Do, let's do OK, let's do this following code.
273
00:20:27,030 --> 00:20:30,120
OK, so do this, all of that.
274
00:20:31,050 --> 00:20:32,970
Let's do while.
275
00:20:35,010 --> 00:20:41,010
Let's do it wild current value is less than zero.
276
00:20:41,250 --> 00:20:44,920
So in this case, these else is also unnecessary.
277
00:20:45,330 --> 00:20:51,810
OK, I've done I've done some modifications with you guys because initially I wanted to talk about it
278
00:20:51,810 --> 00:20:52,230
with you.
279
00:20:52,260 --> 00:20:54,270
So what will be the case here?
280
00:20:54,600 --> 00:20:55,210
The case here?
281
00:20:55,230 --> 00:21:02,130
We will ask the user to insert the value as long as a value is not on.
282
00:21:03,700 --> 00:21:12,010
Is not greater or equal to zero, so now it will look a little bit, ah, a little bit different.
283
00:21:12,040 --> 00:21:13,350
Let's see how it looks like.
284
00:21:13,810 --> 00:21:17,140
I don't know what really what's what's option what option is better.
285
00:21:17,140 --> 00:21:23,550
But let's say that we as here three or so, one minus one and then two, three.
286
00:21:23,590 --> 00:21:29,050
OK, so, um, and also.
287
00:21:29,560 --> 00:21:30,030
Yeah.
288
00:21:30,040 --> 00:21:36,220
I'm not sure that this option works better, you know, because we don't see that we had some problem.
289
00:21:36,820 --> 00:21:42,750
And so these option also can be optimized and um.
290
00:21:43,860 --> 00:21:52,630
Yeah, no actually guys that was kind of kind of a question, but I think that the better option would
291
00:21:52,630 --> 00:22:01,590
be simply to get it back as it was previously, because you see, there is no actual reason to do the
292
00:22:01,600 --> 00:22:02,470
while here.
293
00:22:02,600 --> 00:22:04,570
At least I don't see it right now.
294
00:22:05,620 --> 00:22:13,450
But once again, it's a good thing to try to see if it works OK, because that's my suggestion is how
295
00:22:13,450 --> 00:22:17,790
to approach exercises of different kinds and of different complexities.
296
00:22:18,430 --> 00:22:26,080
Give it a try because you don't know if it will work for one hundred percent and like to take a look
297
00:22:26,080 --> 00:22:31,570
and think about what what would happen if we have used here a while loop do while look, maybe it will
298
00:22:31,570 --> 00:22:32,410
improve a little bit.
299
00:22:32,530 --> 00:22:37,480
My code, like in this example, I think it made a great improvement.
300
00:22:38,080 --> 00:22:43,570
Of course we could have done here also something different, but it's also OK.
301
00:22:44,680 --> 00:22:48,820
So yeah, guys, this is it for this video.
302
00:22:48,820 --> 00:22:51,100
This was not an easy video, right.
303
00:22:51,130 --> 00:22:55,480
Because we covered a lot and this exercise is not this simple one.
304
00:22:56,560 --> 00:23:03,460
So once again, we found a sequence is very ascending or not based on getting these inputs from the
305
00:23:03,460 --> 00:23:09,070
user of an unknown size of a varying size sequence size that we got from the user.
306
00:23:09,400 --> 00:23:19,900
We used the very ascending flag to find if a sequence was basically ascending or not.
307
00:23:20,320 --> 00:23:22,470
And yeah, this is it.
308
00:23:22,480 --> 00:23:25,570
Let me check if I have anything else to add here.
309
00:23:28,000 --> 00:23:35,560
And yeah, there is actually one thing that I wanted to add here is regarding this condition where we
310
00:23:35,560 --> 00:23:40,270
are going to work with the flag, where we are going to modify the flag itself.
311
00:23:40,270 --> 00:23:43,420
So let's simply copy this flag here.
312
00:23:44,440 --> 00:23:46,300
And I want to ask you a simple question.
313
00:23:46,990 --> 00:23:57,100
Once we found out the sequence is not very ascending, then what is the reason to keep on running additional
314
00:23:57,100 --> 00:23:58,980
iterations inside of this loop?
315
00:23:59,320 --> 00:24:06,610
So let's say you had a sequence of thousands of thousands of elements and all of the elements, let's
316
00:24:06,610 --> 00:24:12,370
say like I don't know, all of them are various sending up to, I don't know, a million.
317
00:24:12,700 --> 00:24:16,300
OK, so it's a million or ten million.
318
00:24:16,300 --> 00:24:17,470
It's a million or so.
319
00:24:17,470 --> 00:24:27,730
But the problem was here that the second element simply breaks the rule and says that this sequence
320
00:24:27,730 --> 00:24:35,620
will not never be will never be very ascending, even if all of these elements are very ascending.
321
00:24:35,620 --> 00:24:37,660
But here we have a problem.
322
00:24:37,690 --> 00:24:39,940
This sequence cannot be very ascending.
323
00:24:40,270 --> 00:24:47,110
So we know that by using this condition and various ascending flag, we'll be equal to zero even if
324
00:24:47,110 --> 00:24:47,620
we run.
325
00:24:47,620 --> 00:24:52,520
These are four or five iterations for a 10 or for the whole sequence.
326
00:24:53,200 --> 00:25:02,060
So there is no reason to execute these whole loop over and over again once this condition has been satisfied.
327
00:25:02,620 --> 00:25:03,880
So what do I mean by that?
328
00:25:04,120 --> 00:25:12,260
I mean, let's simply break out of this for for a loop once we found that this condition is true.
329
00:25:12,700 --> 00:25:16,660
OK, so we said the various landing flag to be equal to zero.
330
00:25:16,870 --> 00:25:22,570
And then we break out of this loop and we simply go here and ask the following question.
331
00:25:22,570 --> 00:25:24,690
We know that this condition will be false.
332
00:25:24,700 --> 00:25:27,070
Then the else is going to be executed.
333
00:25:27,310 --> 00:25:36,460
This else is executing when the variable very ascending flag will be equal to, for example, zero.
334
00:25:36,460 --> 00:25:36,910
Right?
335
00:25:37,100 --> 00:25:39,660
Basically not equal to one.
336
00:25:40,810 --> 00:25:47,340
So, yeah, that's a sign that is the optimized solution for this exercise.
337
00:25:48,220 --> 00:25:50,980
So, guys, I hope you like this video.
338
00:25:51,430 --> 00:25:53,950
Please leave me some feedback, some review.
339
00:25:53,990 --> 00:25:57,490
Let me know what you think of the course of the material so far.
340
00:25:58,030 --> 00:26:02,170
And yeah, I think I will see you in the next video, probably.
341
00:26:02,170 --> 00:26:02,530
Right.
342
00:26:03,620 --> 00:26:11,180
So my name is Vlad, this is Alphatech, and guys have a great day, only positive vibes.
343
00:26:11,840 --> 00:26:13,930
And until next time, I'll see you then.
33482
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.