All language subtitles for 3. GDScript Intro Flow Control

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
hu Hungarian
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
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

0 Now that we can store data and manipulate values, we need to discuss about code execution. And the code 1

executes from top to bottom without stopping. 2

Of course, an algorithm cannot be created just by lines of code written without any flow control. 3

This is why in this section we will be discussing about flow control instructions. And they're very 4

important because otherwise nothing will be possible with programming. 5

So let's find out some flow control instructions. 6

Firstly, we need to discuss the IF instruction because this one is the most common. And IF is very simple, 7

you just use the operator IF and then a statement that needs to resolve in either true or false. 8

In this case, I'm using the operator double equals (==), which actually compares. 9

It doesn't assign it compares the value from "a" with 1. 10

And since this is actually true, this will return true. 11

So in this case, if we'll go through the first section which will execute this part of the code, if 12

"a" wasn't equal with 1, then it would have went to the else branch and it would execute that part 13

of the code. 14

Keep in mind that the else branch is optional so it can be completely removed if not necessary. 15

For example, a code can be just if "a" == 1 do something. 16

If not, then I don't care about that part of the code. 17

Now let's look at another important function which is similar with IF but has something particular. 18

This one is called the MATCH instruction. 19

And in other programming languages you might be familiar with the instruction SWITCH because it's very 20

similar. 21

So the main difference between an IF statement and the MATCH statement is the fact that in a IF statement 22

we can have a statement made out of multiple instructions. 23

Well, here in MATCH we have a variable, let's say "a", and then if that variable has multiple numbers 24

or strings that can be, then it's much easier to write this. 25

Keep in mind that with IF we can actually implement a MATCH instruction, but with a MATCH, we 26

cannot really implement a complete IF instruction. In some cases, for example, in this one we can, 27

but in some others we cannot. 28

Let's quickly look at how we can implement this MATCH with an IF. 29

If "a" == 1, then. 30

Print is one. 31

And then there is another instruction called else if (ELIF) it's basically else and if combined and "a" == 2 32

print is 2. 33

We could have opted for this implementation. 34

But as you can see, if we add more values here like three, four, etc., then the MATCH is much more 35

pleasant for the eye to parse rather than using an IF statement. 36

So you might be considering what to use based on what values you are comparing. 37

While the IF instruction and the MATCH instruction actually branch out the code, we have other types 38

of flow control which actually deal with looping code. 39

And the most common one is the FOR instruction. And the FOR instruction works like this: 40

We have a value and we can give it a range, a list and some other things to iterate. Also FOR might 41

be called the iteration operator because what it does, it goes through a list of values and parses 42

each one of them. 43

So if we were to run this, it will print zero, one, two, three, four. 44

Let's see. 45

So for the FOR instruction, we have zero one, two, three, four, because it starts from zero. 46

And of course, it needs to be lower than five to actually finish. 47

One pro of the FOR instruction is the fact that we can iterate lists like the one described in the previous 48

example and also ranges. 49

So for example, counting and so on, so forth. 50

One disadvantage for the FOR instruction is the fact that we cannot parse values that we cannot count. 51

And for this we can use the WHILE instruction. 52

The WHILE and FOR are very similar in a lot of cases because they both loop code, they both work in 53

similar ways because they test the condition to loop another time. 54

But one major difference is the fact that the FOR knows exactly how many steps it needs to take and 55

the WHILE doesn't. 56

In this example, we can clearly see what that means. 57

For example, we have the HP of the player and then we will subtract different values. 58

In fact, random values from that. 59

HP until it reaches zero. 60

This might be, for example, while health is more than zero, but we don't know exactly how much because 61

in this range we actually subtract from 10 to 30 points. 62

And then by just running this, we can see that sometimes this happens with less steps and some 63

other times if more steps. Let's quickly try it. 64

So I'm going to press F6. 65

So in this case. 66

We started with 100. 67

And then the health decreased. 68

And then we ended up with seven steps. 69

Let's run it again. 70

Now it seems that the random did a better job, so we ended up with six steps. 71

This could not have been implemented with a FOR. 72

Now let's look at functions.

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