Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
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.