Hello and welcome to the Golang programming language course in this session.
We want to talk about loops and control statements.
Loops in go language go.
Language contains only a single loop that is for loop, if for loop is a repetition control structure
that allows us to write a loop that is executed a specific number of times and go language, these four
loop can be used in the different forms, and the forms are simple for loop.
Loop as infinite loop.
And for law as vice.
As simple for a loop, a for loop is used for iterating over cycles, that is either a slice and or
a map or string.
It is similar that we used in the other programming languages like C, C++, Java, C-sharp and et cetera.
Now you can see the syntax.
Here, the initialization a statement is optional and executes P4 for loop starts.
The initialization, a statement is always in a simple statement like variable declarations, increment
or assignment statements or function calls the condition.
The statement holds a Boolean expression, which is evaluated at the start of each iteration of the
loop.
If the value of the conditional statement is true, then the loop executes
increment or the post.
The statement is executed after the body of the for loop after the post, the statement, the condition,
the statement evaluate the gain.
If the value of the conditional statement is false, then the loops end.
Now let's go to the escort program to illustrate how to use for loop.
First, go to Project Explorer, create a project folder name like loops and create a file inside.
It's like main that go defined package name
and defined main function.
OK, first, define a scene per for loop four.
So you write for define a variable for initialization, for example, I column he equals and initialize
it by zero semicolon and defined conditions for this for loop, for example, I less than five.
In this case, we want to print numbers between 0.5 semicolon, and if we want to increment all variable
one by one, so we write I plus plus or can enclose kind of racist.
And we write the statements in curly braces.
So we write f f i equals person d put a backslash d for a tabitha's and type a message, for example,
go pro gram language and set it back in session for go to a new line and define value that I.
OK.
These loops start when I equals zero and executed until I less than five.
Now, save the project, go to a terminal and execute the program.
First, go to Project Folder, see the loops, a screen and run the program by the comment.
Go from dots back English made that go.
Now we can see the output.
We could print that go programming language five times by simper for loop from AI equals zero until
AI equals four.
In order not to prolong the time of decision, we will finish it and we will continue with the content
in the next session.
Goodbye.