WEBVTT 00:00.360 --> 00:06.540 This is the third video of this section flow control in the previous video we started with the program 00:06.660 --> 00:09.720 to display hello world in this video. 00:09.750 --> 00:17.460 We will use the if else statement the switch statement and the full range statement flow control is 00:17.460 --> 00:23.820 referred to as the ability to decide which portion of code or how many times you execute some code on 00:23.820 --> 00:25.800 a condition in go. 00:25.800 --> 00:33.240 It is implemented using familiar imperative clauses like if else switch and or the syntax is easy to 00:33.240 --> 00:34.230 grasp. 00:34.230 --> 00:38.130 Let us review major flow control statements in go. 00:38.130 --> 00:42.250 So we start with the first one that is the if else statement. 00:42.450 --> 00:49.080 Go language like most programming languages has if else conditional statement for flow control the syntax 00:49.080 --> 00:54.630 is similar to other languages but you don't need to encapsulate the condition between parentheses. 00:54.660 --> 01:00.840 Here's how we use it as you can see the main function starts with the variable value followed by the 01:00.930 --> 01:07.440 if statement with the condition and the print statement when the condition is true and the print within 01:07.530 --> 01:10.890 else will be printed when the condition is false. 01:11.010 --> 01:17.700 Let's run this and see the output so you can see the print within elses given as output because 10 is 01:17.700 --> 01:19.820 not equal to 20. 01:19.830 --> 01:26.130 Now the else if condition works in a similar fashion you don't need parentheses either and they are 01:26.130 --> 01:29.010 declared as programmers would expect. 01:29.010 --> 01:37.320 Let me add the lines of code for this so it contains if else F and else conditions let's execute this 01:37.320 --> 01:41.330 program so the output is 10 is equal to 10. 01:41.340 --> 01:44.730 Cool we got this output based on the condition. 01:44.910 --> 01:50.140 A equal to be 10 equal to 10 and true equal to False. 01:50.250 --> 01:51.620 Else if eleven. 01:51.720 --> 01:55.210 Equal to eleven and go equal to go. 01:55.380 --> 02:03.050 We print the second statement or else we print the last statement that is in case no condition is satisfied. 02:03.060 --> 02:10.620 Print this go does not have ternary conditions like condition with question mark sign and true colon 02:10.650 --> 02:11.890 pulse. 02:12.090 --> 02:15.030 Next let's touch the switch statement. 02:15.290 --> 02:19.310 So the switch statement is also similar to most imperative languages. 02:19.370 --> 02:22.780 You take a variable and check possible values for it. 02:22.820 --> 02:25.130 Let's take an example to understand this. 02:25.250 --> 02:29.540 So the switch condition here is no should be three. 02:29.570 --> 02:35.230 We have added three conditions so we can be sure that we should get the third statement as the output. 02:35.720 --> 02:38.300 Let's run and check the output. 02:38.300 --> 02:42.880 The third case is satisfied and we get the output as three. 02:42.980 --> 02:44.840 Moving on to the last one. 02:45.020 --> 02:48.060 That is the full range statement. 02:48.200 --> 02:54.530 The for loop is also similar than in common programming languages but you don't use parentheses either. 02:54.650 --> 03:01.970 We use the logic for IE is equal to zero ie less than equal to Xen ie plus plus 03:05.070 --> 03:10.710 and we print all the values of IE for this condition as you have probably imagined. 03:10.740 --> 03:17.630 If you have a computer science background we infer an entire variable defined as 0 and execute the code 03:17.640 --> 03:23.760 between the brackets while the condition ie less than or equal to zero is satisfied. 03:23.760 --> 03:28.370 Finally for each execution we add one to the value of ie. 03:28.380 --> 03:36.100 This code prints the numbers from zero to 10 you have a special syntax to iterate over arrays or slices 03:36.310 --> 03:38.860 which is range which I add here. 03:38.860 --> 03:47.890 So for index value range my array we print index is Ampersand D and value is am present day with the 03:47.890 --> 03:50.810 values of index and value for D. 03:50.890 --> 03:57.880 First the F empty format is a very common go package that we will use extensively to give shape to the 03:57.880 --> 04:00.520 message that we will print in the console. 04:00.730 --> 04:07.750 Regarding 4 you can use the range keyword to retrieve every item in a collection like my array and assign 04:07.750 --> 04:10.480 them to the value temporal variable. 04:10.480 --> 04:15.190 It will also give you an index variable to know the position of the value you're retrieving. 04:15.190 --> 04:17.830 It's equivalent to write this code. 04:17.830 --> 04:20.920 This is the basic syntax for loop. 04:21.280 --> 04:25.060 The Len method is used to know the length of a collection. 04:25.060 --> 04:30.300 If you execute this code you'll see that the result is the same in this video. 04:30.320 --> 04:36.080 We've learned about different statement to use of flow control in go in the next video. 04:36.100 --> 04:39.010 We will dive into the functions with go.