All language subtitles for 11. Do-While Loops - C Programming Language

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

So what are the do while loops?

Let's say that we would like to make a simple program that will help Sellar seen supermarkets to sum

up the price of all products in a given or other.

So the seller is probably going to some the prices for each product, something like one plus two plus

one plus five and so on.

Right.

Let's live it as in the jurors.

For this example, though, in the real life, it will probably be of a floating point type.

But that's something that we can modify when whenever we like.

So we want to develop a program that all it will do is simply this operation.

It will sum up all the prices until a given price.

Let's say zero will be inserted.

All right.

I mean, it makes sense to use a zero price as a stepping condition because it simply wants change the

total price and nothing in our code.

So basically, to summarize, the seller will insert prices of different products one after the other.

And once he will insert a zero, this will mean that the order is completed and that we have to print

the total price to let the customer pay what he has to pay.

So let's take a closer look to see how it looks like in our program in see, I've just added it here

for you guys that we will be more convenient for us to take a look.

So first of all, we create two variables a price variable and a total price variable, which will hold

the total amount of all the prices for all the products we've inserted so far and the price that will

simply read a given price at every time and every duration because we are going to use Loop's here.

So we first of all, like in the previous milestone, we print a nice message, please enter a price.

Then we read the value of the price and story and say the price variable.

And then we test how the condition wild price does not is not equal is to zero.

We are going to run the loop body and in the loop body.

We are going to add the given price to the total price and read the next price one after the other and

so on.

Until we reach a price of zero and once we reach the price of zero, we simply are going to get out

of the slope and to print the total or their price, which will be the total price, the value in inside

of this variable.

But if we are to take a closer look at this program, we can clearly see that there are two repeating

lines here.

These print F and SCANA flying these two lines and these two lines that they are basically identical.

So we can see that we have some sort of code duplication.

And it's basically just unnecessary.

We should try to avoid code duplications whenever we can.

So what basically can we do about eating this example?

Can we do something differently or should we just leave it as is?

These code duplicating two places.

And as the title suggests, we are going to use here another structure of loops, not the while loop,

as we've seen here and exactly as we've done in the previous milestone.

We are going to use do Wyles in do while loops in C.

So how A do while looks like.

Let's see.

So it's very similar to a while loop.

All right.

It's very similar.

It's do while and there is while.

There is a do while.

And it looks like the following.

First of all you specify first counts the do statement and then you have the curly brackets that specify

the block of commands that that there is going to be on there, which is actually the loop body.

And the commands here are going to be pretty much the same as they were in the while loop.

So you just preens print out a corresponding message to the user to enter a price and then you read

a value from the console.

Then you add it to the thall a total price and then you specify that it's all of these curly bracket

is the loop body and it's going to run while the price is not equals to zero.

So basically it's the same as the previous while loop.

The only difference is that the first time we are going to hit that do while loop, the first time we're

going to come here, we will run all of the loop body commands, regardless of the condition, regardless

if the price is zero or not.

We are, first of all, going to execute the loop body for the first time.

Then we are going to check the condition.

And if the condition.

True.

We are going to run it once again.

And if it falls, we are going to step out of the slope and to proceed with this line.

So pretty simple.

We run the commands regardless of the condition, and then we check the condition and run the durations

over and over again, just like using the standard while loop that we've seen previously.

So that's pretty simple, guys.

The logic is pretty straightforward.

All you have to do is probably just get used this syntax in C language.

And just to make it more clear to you.

Let's make a comparison, a full comparison with the while loop, how the code maps from one one type

of form of writing the code to another type of writing.

These the same code.

One option we use the while loop.

And the second option we the do while loops.

So the first two lines that we've seen previously, that print F and the scanner.

That was before we entered the wire loop is actually mapped.

There was this guy.

We can see that in both cases.

These two lines are going to be executed regardless of their result of these conditions here or these

conditions here.

And we can see that we have also on both sides the wild statement, the wild statement and the condition,

which is just the same.

Right.

It specifies the loop condition and it will be whenever the price will be, it will equal to zero.

All we will step out of this loop.

So it's the same in both cases.

And also, if we take a look at the loop body in the wild.

In the wild structure, it is the same.

All right.

If you take a look at these the same, just that the total price here is a third line while here, it's

in the first line.

So it's mapped pretty much the same way as we've done it in the wild love.

So the same with the do while the body is pretty much the same.

Just organized a little bit different.

So what we can learn here is that in this case, where in this such cases, let's say when we know that

the same commands command one command, a couple of comments should be executed before before the little

body.

And also the same commands are going to be executed inside of the loop, buddy.

In these cases, we are going to prefer to use a do wild structure because we want to eliminate the

usage of code duplication.

When whenever we we actually can, because code applications are very hard to maintain.

And for example, if on another day you will find out that here in the Preened Def Command, you want

to just change the message, print it out through the screen.

Then you have to remember that you must change all all of the messages that are duplicated inside of

this code.

And to tell you the truth.

That's not something that happens.

You will, if you will, use code duplications.

You are actually going to probably experience a lot of bugs in your program that are not so easy to

detect.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.