WEBVTT 1 00:00:05.646 --> 00:00:09.883 Game Basics Control Statements 2 00:00:09.883 --> 00:00:12.127 GCC Academy 3 00:00:27.594 --> 00:00:29.495 Hello everyone 4 00:00:29.495 --> 00:00:33.881 This is Lee Young-hoon for C#-based object-oriented programming course 5 00:00:33.881 --> 00:00:37.281 This section covers commonly used conditional statements 6 00:00:37.281 --> 00:00:39.515 and loop statements 7 00:00:39.515 --> 00:00:43.215 Using the if statement, we will learn about branching based on values 8 00:00:43.215 --> 00:00:46.277 and conditional branching 9 00:00:46.277 --> 00:00:48.477 as well as switch statements and 10 00:00:48.477 --> 00:00:51.584 branching based on values 11 00:00:51.584 --> 00:00:54.684 We willl also learn how to do repetitive processing 12 00:00:54.684 --> 00:00:57.218 using for statements and while statements 13 00:00:57.218 --> 00:01:00.318 and ending loop or 14 00:01:00.318 --> 00:01:04.000 skipping certain tasks with jump statement 15 00:01:04.451 --> 00:01:08.371 if statement, switch statement 16 00:01:09.000 --> 00:01:11.750 Control statements are used to control 17 00:01:11.750 --> 00:01:14.000 the flow of a program 18 00:01:14.000 --> 00:01:19.703 Important control statements include conditional statements and loop statements 19 00:01:19.703 --> 00:01:24.208 In conditional statements, there are things like if statements and switch statements 20 00:01:24.208 --> 00:01:29.871 And there are loops such as for loops and while loops 21 00:01:29.871 --> 00:01:32.475 Let's learn them one by one 22 00:01:32.475 --> 00:01:36.000 First, let's learn about if statements 23 00:01:36.000 --> 00:01:38.501 To do this 24 00:01:38.501 --> 00:01:41.436 Shall we create a simple project first? 25 00:01:41.436 --> 00:01:44.322 Open solution 26 00:01:44.322 --> 00:01:47.272 Right click here and add 27 00:01:47.272 --> 00:01:49.875 Let me add one more project 28 00:01:52.920 --> 00:01:54.820 Likewise, the console app 29 00:01:54.820 --> 00:01:58.420 Click on the part that says (.NET Framework) 30 00:01:58.420 --> 00:02:02.320 Since this is a control statement, control statements are usually in English 31 00:02:02.320 --> 00:02:04.320 Control Statement 32 00:02:04.320 --> 00:02:06.370 So I'll write it like this 33 00:02:06.370 --> 00:02:12.088 Let's write ControlStatement 34 00:02:18.084 --> 00:02:23.080 Let's create a project like this first 35 00:02:23.080 --> 00:02:25.880 Then let's try the if statement first 36 00:02:25.880 --> 00:02:28.447 Let me explain it briefly 37 00:02:31.880 --> 00:02:36.030 if statement is written like this 38 00:02:36.030 --> 00:02:39.119 It says if and then there are parentheses here 39 00:02:39.119 --> 00:02:42.919 Then the curly brackets go in like this 40 00:02:42.919 --> 00:02:46.604 Curly brackets are what I called scope last time 41 00:02:46.604 --> 00:02:52.311 This is a domain, but the term scope is often used 42 00:02:52.311 --> 00:02:57.080 So there is something called if and there is a condition in it 43 00:02:57.080 --> 00:03:03.279 Here is a condition and if this condition is true 44 00:03:03.279 --> 00:03:07.757 I said that true is true in English 45 00:03:07.757 --> 00:03:13.907 If true, the contents inside will be executed 46 00:03:13.907 --> 00:03:19.000 If it is false, it will not do anything and will immediately end this scope 47 00:03:19.000 --> 00:03:24.600 And the if statement can also be written as a single statement like this 48 00:03:24.600 --> 00:03:27.950 This is a condition, like yes or no 49 00:03:27.950 --> 00:03:29.800 You can do it dichotomously too 50 00:03:29.800 --> 00:03:34.000 That means, write else here 51 00:03:34.000 --> 00:03:36.650 Also, if you make the scope like this 52 00:03:36.650 --> 00:03:43.000 If this is true, the contents of this side will be executed 53 00:03:43.000 --> 00:03:48.000 If this is false, the else statement is executed 54 00:03:48.000 --> 00:03:50.959 You can make it like this in two ways 55 00:03:50.959 --> 00:03:54.559 In this way, there are not two conditions 56 00:03:54.559 --> 00:03:57.259 It branches out into three or four 57 00:03:57.259 --> 00:03:58.559 or more 58 00:03:58.559 --> 00:04:01.509 In that case, write it like this 59 00:04:01.509 --> 00:04:03.647 If 60 00:04:05.924 --> 00:04:10.196 Then say else if 61 00:04:13.039 --> 00:04:14.626 Finally else 62 00:04:17.713 --> 00:04:20.013 You can also write it like this 63 00:04:20.013 --> 00:04:24.181 This is also a set, so if this is true 64 00:04:24.181 --> 00:04:26.963 Here is the execution and it ends 65 00:04:26.963 --> 00:04:30.613 If it is false, then come back to else if 66 00:04:30.613 --> 00:04:32.240 Check the conditions 67 00:04:32.240 --> 00:04:34.574 If this is true, then it's doing this 68 00:04:34.574 --> 00:04:38.924 Otherwise, go to the else statement and do the work here 69 00:04:38.924 --> 00:04:43.200 It's structured in such a way that it ends the whole thing 70 00:04:43.200 --> 00:04:46.900 So, let's try coding this ourselves 71 00:04:46.900 --> 00:04:49.982 Let's try it with an example 72 00:04:52.439 --> 00:04:55.689 Let me make an example 73 00:04:55.689 --> 00:04:58.119 of getting an age input and outputting it 74 00:04:58.119 --> 00:05:02.369 So, let me write it down as a comment 75 00:05:02.369 --> 00:05:06.703 Get age input 76 00:05:08.560 --> 00:05:13.357 If you are 20 years old 77 00:05:14.680 --> 00:05:19.749 You are 20 years old 78 00:05:19.749 --> 00:05:22.249 Such a sentence will be output 79 00:05:22.249 --> 00:05:24.199 in this example 80 00:05:24.199 --> 00:05:29.080 We have done output first so far, but input is also possible 81 00:05:29.080 --> 00:05:32.919 How to use input, in the console 82 00:05:32.919 --> 00:05:39.027 let's try it with ReadLine. ReadLine 83 00:05:39.027 --> 00:05:43.627 This basically returns a string 84 00:05:43.627 --> 00:05:45.879 So it's returning a text 85 00:05:45.879 --> 00:05:48.379 That's why it's called a string 86 00:05:48.379 --> 00:05:51.724 Since it was input, let's call it inputString 87 00:05:57.218 --> 00:05:59.492 If you do this, something will come in 88 00:05:59.492 --> 00:06:02.120 If you press enter, the value will be inserted here 89 00:06:02.120 --> 00:06:05.216 Let's output this first 90 00:06:08.760 --> 00:06:11.110 Console, WriteLine 91 00:06:11.110 --> 00:06:15.090 Auto-completion looks like this Let's run it 92 00:06:15.090 --> 00:06:19.440 Just hold down Ctrl and press F5, like this 93 00:06:19.440 --> 00:06:22.740 When I do this, the cursor blinks like this 94 00:06:22.740 --> 00:06:25.810 If you type 20 here and press enter 95 00:06:25.810 --> 00:06:29.616 You can see that 20 is output 96 00:06:29.616 --> 00:06:32.559 So it's like this here 97 00:06:32.559 --> 00:06:35.859 So you want to write it like this here 98 00:06:35.859 --> 00:06:39.009 Your age is, you are 20 years old 99 00:06:39.009 --> 00:06:41.779 I'll try outputting it like this 100 00:06:41.779 --> 00:06:45.029 Like this, then 101 00:06:45.029 --> 00:06:48.720 You need to check if it was entered correctly 102 00:06:48.720 --> 00:06:52.370 So I'm going to check if this is 20 103 00:06:52.370 --> 00:06:55.720 A simple way to check is if 104 00:06:55.720 --> 00:06:59.970 Since we're learning about conditional statements, I'm going to try using a conditional statement 105 00:06:59.970 --> 00:07:04.039 Say if and then open parentheses like this 106 00:07:04.039 --> 00:07:06.589 Then, the conditional expression comes in here 107 00:07:06.589 --> 00:07:11.960 Then, create an area here with curly brackets like this 108 00:07:11.960 --> 00:07:17.655 I'm going to put this content in this area like this 109 00:07:17.655 --> 00:07:21.520 Then, if this condition is true, this will be output 110 00:07:21.520 --> 00:07:24.320 And if this condition is wrong 111 00:07:24.320 --> 00:07:27.924 You can make it like this by saying else 112 00:07:27.924 --> 00:07:30.596 Create an else statement 'it is not applicable' 113 00:07:36.888 --> 00:07:38.938 This will be output 114 00:07:38.938 --> 00:07:42.909 Then, inputString must have the value 20 115 00:07:42.909 --> 00:07:45.823 If we compare with strings 116 00:07:45.823 --> 00:07:49.279 You can make a comparison like this 117 00:07:49.279 --> 00:07:53.962 So let's run like this 118 00:07:53.962 --> 00:07:56.962 If you do this and press 20 enter like this 119 00:07:56.962 --> 00:07:59.012 You are 20 years old 120 00:07:59.012 --> 00:08:01.440 You can see the output like this 121 00:08:01.440 --> 00:08:04.190 And then run it again 122 00:08:04.190 --> 00:08:06.679 Let's try outputting a value other than 20 123 00:08:06.679 --> 00:08:10.279 21, This does not apply 124 00:08:10.279 --> 00:08:12.929 So you can see that it is output like this 125 00:08:12.929 --> 00:08:17.199 If you write a conditional statement like this, it becomes a set 126 00:08:17.199 --> 00:08:21.871 So, you can use it like this as a single word 127 00:08:21.871 --> 00:08:23.444 And in this complex way 128 00:08:23.444 --> 00:08:25.399 You can also add one more 129 00:08:25.399 --> 00:08:30.794 If we add one else if like this 130 00:08:30.794 --> 00:08:34.679 You can do something like this by adding more conditions 131 00:08:34.679 --> 00:08:37.579 I'll try it here like 21 132 00:08:37.579 --> 00:08:40.451 21 133 00:08:40.451 --> 00:08:43.581 21, check, and compare 134 00:08:43.581 --> 00:08:46.012 You are 21 years old It's also output like this 135 00:08:46.012 --> 00:08:49.027 I'll put that here 136 00:08:49.027 --> 00:08:52.827 ctrl+F5, and it works well 137 00:08:52.827 --> 00:08:56.679 So if we say 21 like this 138 00:08:56.679 --> 00:08:59.929 Look, this is what it says, you are 21 years old 139 00:08:59.929 --> 00:09:02.529 If you look here == it's written like this 140 00:09:02.529 --> 00:09:06.519 This is called a comparison operator 141 00:09:06.519 --> 00:09:09.569 There are things called comparison operators and logical operators 142 00:09:09.569 --> 00:09:13.440 The comparison operator is ==, this is equal 143 00:09:13.440 --> 00:09:17.540 So, if A and B are equal, then it is true 144 00:09:17.540 --> 00:09:19.890 And this is called not 145 00:09:19.890 --> 00:09:21.440 not equal 146 00:09:21.440 --> 00:09:24.840 So if A and B are not equal 147 00:09:24.840 --> 00:09:27.340 If it's different, it's true 148 00:09:27.340 --> 00:09:32.760 This is an inequality, so if A is greater than B 149 00:09:32.760 --> 00:09:36.060 If less than, greater than or equal to, less than or equal to is true 150 00:09:36.060 --> 00:09:38.010 There are operators like this 151 00:09:38.010 --> 00:09:40.920 These operators are called comparison operators 152 00:09:40.920 --> 00:09:43.320 or also called relational operators 153 00:09:43.320 --> 00:09:45.870 And the one below are logical operators 154 00:09:45.870 --> 00:09:47.709 It's a bit like a set concept 155 00:09:47.709 --> 00:09:52.370 So if both condition A and condition B are true 156 00:09:52.370 --> 00:09:54.000 it's true with this operator 157 00:09:54.000 --> 00:09:56.350 This is an ampersand 158 00:09:56.350 --> 00:10:00.679 This is called and, this is and 159 00:10:00.679 --> 00:10:03.162 And you see on the keyboard 160 00:10:03.162 --> 00:10:05.762 There is a won sign above the Enter key 161 00:10:05.762 --> 00:10:07.880 Above the won sign 162 00:10:07.880 --> 00:10:13.055 there is a stick like symbol, and it's called the or operator 163 00:10:13.055 --> 00:10:18.332 So if we use the or operator like this A || B, 164 00:10:18.332 --> 00:10:21.532 If either A or B is true 165 00:10:21.532 --> 00:10:23.880 It's true if either one of them is true 166 00:10:23.880 --> 00:10:29.032 And this is called not 167 00:10:29.032 --> 00:10:31.132 It's a concept that turns things around 168 00:10:31.132 --> 00:10:33.932 If A is true, then it is false 169 00:10:33.932 --> 00:10:36.276 True when A is false 170 00:10:36.276 --> 00:10:41.119 Such operators are called logical operators 171 00:10:41.119 --> 00:10:46.079 Then let's try or first 172 00:10:46.079 --> 00:10:49.440 20 years old or 173 00:10:49.440 --> 00:10:52.433 Or 21 years old 174 00:10:56.859 --> 00:11:00.459 Let's change the content like this 175 00:11:00.459 --> 00:11:04.878 Should I give a scope like this this time? 176 00:11:04.878 --> 00:11:07.428 So now if we compare this to a string 177 00:11:07.428 --> 00:11:09.528 It's a bit difficult to deal with the scope 178 00:11:09.528 --> 00:11:11.600 So let me convert this into numbers 179 00:11:11.600 --> 00:11:14.850 It was given the number 20 180 00:11:14.850 --> 00:11:18.350 Because this is now processed as a string 181 00:11:18.350 --> 00:11:21.720 You can convert a string to a number 182 00:11:21.720 --> 00:11:25.120 So this to an int type, an integer type 183 00:11:25.120 --> 00:11:28.120 Create a variable called age 184 00:11:28.120 --> 00:11:32.399 Let's make the input String into an integer variable 185 00:11:32.399 --> 00:11:35.899 If you write int and press the dot here 186 00:11:35.899 --> 00:11:38.699 Any function that int has 187 00:11:38.699 --> 00:11:40.559 Things like these properties come out 188 00:11:40.559 --> 00:11:42.659 There's something called Parse here 189 00:11:42.659 --> 00:11:45.159 Parse, it's written here 190 00:11:45.159 --> 00:11:48.995 The representation of a character as a corresponding signed integer 191 00:11:48.995 --> 00:11:51.967 It's a function that converts it, so if you look at it 192 00:11:51.967 --> 00:11:55.367 If you write int.Parse and put a character here, 193 00:11:55.367 --> 00:11:59.217 If this is a number, it is automatically converted to an integer variable 194 00:11:59.217 --> 00:12:01.519 It's a feature that automatically does that 195 00:12:01.519 --> 00:12:05.696 So I'm going to write it like this 196 00:12:05.696 --> 00:12:10.059 Then the value of age is 20 or something like 21 197 00:12:10.059 --> 00:12:12.159 The values ​​entered like this will be stored 198 00:12:12.159 --> 00:12:16.897 Then, change it like this 199 00:12:17.680 --> 00:12:21.921 Then don't write like this 200 00:12:21.921 --> 00:12:27.865 I want to write the age range as I am in my 20s 201 00:12:27.865 --> 00:12:30.265 You are in your 20s 202 00:12:30.265 --> 00:12:34.417 If we express the 20s as the age from 20 to 29, 203 00:12:34.417 --> 00:12:40.799 You can write it like this: greater than or equal to 20 204 00:12:40.799 --> 00:12:46.099 Then, the value called age, the value contained within age 205 00:12:46.099 --> 00:12:50.320 is greater than or equal to 20, this is a bit wrong 206 00:12:50.320 --> 00:12:52.188 I think this should be && 207 00:12:52.188 --> 00:12:55.497 Sorry, let me do and first 208 00:12:55.497 --> 00:12:59.599 The value of age is greater than or equal to 20 and 209 00:12:59.599 --> 00:13:02.999 it should be less than 30 210 00:13:02.999 --> 00:13:07.023 Or you could say 29 or less 211 00:13:07.023 --> 00:13:10.973 Let's try and first, this is and, so it's an intersection 212 00:13:10.973 --> 00:13:16.090 So the value in age is greater than or equal to 20 213 00:13:16.090 --> 00:13:20.140 And if it is less than or equal to 29 That's what this means 214 00:13:20.140 --> 00:13:24.717 So this is now between 20 and 29, right? 215 00:13:24.717 --> 00:13:28.367 Only the range within it is now applicable to this side 216 00:13:28.367 --> 00:13:31.017 Otherwise, it will go to the not applicable side 217 00:13:31.017 --> 00:13:34.040 Let me test it 218 00:13:34.040 --> 00:13:38.090 Do this and press ctrl+F5 219 00:13:38.090 --> 00:13:40.540 Let's try entering the age 220 00:13:40.540 --> 00:13:45.720 If you enter 20 years old, it will naturally say you are in your 20s 221 00:13:45.720 --> 00:13:48.220 25 is still 20s, right? 222 00:13:48.220 --> 00:13:52.470 But if you're 19, then this doesn't apply 223 00:13:52.470 --> 00:13:55.160 This is how you can handle branching 224 00:13:55.160 --> 00:13:57.310 Then I'll try or too 225 00:13:57.310 --> 00:14:02.959 else if, the range is 20s like this 226 00:14:02.959 --> 00:14:11.299 If age is 30, or if age is 31 227 00:14:16.160 --> 00:14:17.556 Then you are 228 00:14:20.853 --> 00:14:26.804 You are 30 or 31 years old 229 00:14:30.279 --> 00:14:32.279 You could express it like this 230 00:14:32.279 --> 00:14:34.320 But usually when we make something like this, 231 00:14:34.320 --> 00:14:36.677 I know this so I type it right away 232 00:14:36.677 --> 00:14:40.240 but if I am to make this and give it to someone 233 00:14:40.240 --> 00:14:41.694 Actually, I don't think it's right to do it like this 234 00:14:41.694 --> 00:14:45.394 So first of all, enter your age here 235 00:14:45.394 --> 00:14:48.360 I think it would be better to guide it in this way 236 00:14:48.360 --> 00:14:49.137 Here 237 00:14:53.520 --> 00:14:54.620 Do it like this 238 00:14:54.620 --> 00:14:58.920 WriteLine means after this sentence 239 00:14:58.920 --> 00:15:01.960 the cursor will move down to the next line 240 00:15:01.960 --> 00:15:06.160 I want to keep the cursor here 241 00:15:06.160 --> 00:15:07.560 I will write it like this 242 00:15:07.560 --> 00:15:12.039 If you write Write, there is no line break 243 00:15:12.039 --> 00:15:14.205 If you run it like this, it will look like this 244 00:15:14.205 --> 00:15:17.505 Here the cursor will blink over here 245 00:15:17.505 --> 00:15:22.320 After I make it like this, I'll put 31 in like this 246 00:15:22.320 --> 00:15:24.615 Then it's over here 247 00:15:24.615 --> 00:15:26.915 Because it doesn't apply here 248 00:15:26.915 --> 00:15:30.537 Because the if statement at the very beginning is false 249 00:15:30.537 --> 00:15:33.987 Then, enter the else if statement 250 00:15:33.987 --> 00:15:35.520 I'm checking here 251 00:15:35.520 --> 00:15:39.270 So if your age is 30 or 31, this applies to you 252 00:15:39.270 --> 00:15:42.670 or is a union, right? 253 00:15:42.670 --> 00:15:44.973 This one or this one, right? 254 00:15:44.973 --> 00:15:47.973 If your age is 30 or 31 255 00:15:47.973 --> 00:15:51.476 This means that it meets this condition, it is true 256 00:15:51.476 --> 00:15:55.706 so this sentence is output 257 00:15:55.706 --> 00:15:58.506 By using comparison operators like this 258 00:15:58.506 --> 00:16:01.506 You can check various things like this 259 00:16:01.506 --> 00:16:05.182 We can create branch statement and use it 260 00:16:05.182 --> 00:16:08.080 for various processing 261 00:16:08.080 --> 00:16:12.430 You can use the if statement by writing it like this 262 00:16:12.430 --> 00:16:17.279 This time, let's try a switch case statement 263 00:16:17.279 --> 00:16:20.392 Let's comment with ctrl+k+c 264 00:16:20.392 --> 00:16:22.245 Comment out the block 265 00:16:25.839 --> 00:16:27.835 Here's the second note 266 00:16:30.759 --> 00:16:37.034 Input from 0 to 2 267 00:16:39.545 --> 00:16:45.559 Let's try an example of outputtig that 268 00:16:45.559 --> 00:16:48.408 This time, I'm going to try using something called a switch case statement 269 00:16:52.873 --> 00:16:54.373 First, we need to get input 270 00:16:54.373 --> 00:16:57.559 Likewise, let's write this as is 271 00:16:57.559 --> 00:17:01.495 I'll write here, "Enter 0 to 2" 272 00:17:06.799 --> 00:17:10.049 Likewise, this can be written as is 273 00:17:10.049 --> 00:17:14.359 I will read one line as inputString 274 00:17:14.359 --> 00:17:18.209 And this time, it is an int integer variable 275 00:17:18.209 --> 00:17:21.399 Let's create a variable called number 276 00:17:21.399 --> 00:17:24.749 I'm going to fill this variable with this value 277 00:17:24.749 --> 00:17:28.119 We tried like this earlier, right? 278 00:17:28.119 --> 00:17:30.419 I used a function called Parse 279 00:17:30.419 --> 00:17:34.069 But there is one more type of function called Parse 280 00:17:34.069 --> 00:17:37.079 So I'll try it another way 281 00:17:37.079 --> 00:17:40.418 It's int 282 00:17:40.418 --> 00:17:46.519 Like this, if you look at int, if you look at Parse 283 00:17:46.519 --> 00:17:48.719 There's also a guy called TryParse 284 00:17:48.719 --> 00:17:51.279 There are two: Parse and TryParse 285 00:17:51.279 --> 00:17:54.524 What this does is it handles exceptions 286 00:17:54.524 --> 00:17:58.374 What that means is, for example, in this string 287 00:17:58.374 --> 00:18:01.359 We want the numbers to be filled in 288 00:18:01.359 --> 00:18:04.409 But in reality, it's not a number 289 00:18:04.409 --> 00:18:07.399 You can also enter English, alphabets 290 00:18:07.399 --> 00:18:09.959 In that case, we're going to have a problem 291 00:18:09.959 --> 00:18:11.659 It's not a number like this 292 00:18:11.659 --> 00:18:14.760 So, if you want to do parsing like this 293 00:18:14.760 --> 00:18:17.960 The word parsing simply means this 294 00:18:17.960 --> 00:18:21.960 Converting any data into the format I want 295 00:18:21.960 --> 00:18:23.799 Those things are usually called Parsing 296 00:18:23.799 --> 00:18:27.149 When you convert it to the desired format 297 00:18:27.149 --> 00:18:30.959 If the format of the data is different, there will be problems 298 00:18:30.959 --> 00:18:33.609 So to prevent things like that 299 00:18:33.609 --> 00:18:36.359 We use the function called TryParse 300 00:18:36.359 --> 00:18:39.859 Here's how to use it. It's written exactly as you can see here 301 00:18:39.859 --> 00:18:43.720 What this means is 302 00:18:43.720 --> 00:18:46.370 If you look here, you can see that two of them are inserted like this 303 00:18:46.370 --> 00:18:49.870 This is a function, and we will learn about functions later 304 00:18:49.870 --> 00:18:51.399 I'll tell you more details then 305 00:18:51.399 --> 00:18:55.222 So, first of all, you can think of it as a feature 306 00:18:55.222 --> 00:18:57.872 So now when we use this guy 307 00:18:57.872 --> 00:19:01.250 I need to enter two pieces of information 308 00:19:01.250 --> 00:19:05.079 If you look at the first information 309 00:19:05.079 --> 00:19:07.579 If you press ctrl+shift+space like this 310 00:19:07.579 --> 00:19:09.625 You can see this content again 311 00:19:09.625 --> 00:19:10.525 Good 312 00:19:10.525 --> 00:19:12.596 Put it in parentheses here 313 00:19:12.596 --> 00:19:16.488 If you hold down ctrl+shift and press the space bar at the same time 314 00:19:16.488 --> 00:19:21.679 You can see the format of this function like this 315 00:19:21.679 --> 00:19:24.379 It's called the declaration, you can see this 316 00:19:24.379 --> 00:19:27.729 So, if you look, there are two pieces of information here 317 00:19:27.729 --> 00:19:29.839 One is a string type 318 00:19:29.839 --> 00:19:32.525 One is int type 319 00:19:32.525 --> 00:19:36.723 So, for the string, put this in, what we received 320 00:19:36.723 --> 00:19:40.880 Then we create a variable that will hold the information about this guy 321 00:19:40.880 --> 00:19:43.980 The result of it This keyword called out 322 00:19:43.980 --> 00:19:48.440 You can think of it as a function needed to return it 323 00:19:48.440 --> 00:19:52.290 Let's go into more detail when we do functions 324 00:19:52.290 --> 00:19:55.790 Usually, functions are with this = 325 00:19:55.790 --> 00:19:58.040 This is how you receive the return value 326 00:19:58.040 --> 00:20:02.754 But this Parse function returns the result like this 327 00:20:02.754 --> 00:20:04.490 I receive it just like this 328 00:20:04.490 --> 00:20:08.040 In the case of TryParse, the return value is bool 329 00:20:08.040 --> 00:20:11.490 The bool type is logical, it comes with true and false 330 00:20:11.490 --> 00:20:15.840 So, I'm converting this 331 00:20:15.840 --> 00:20:18.399 When you want to know whether it was a success or a failure 332 00:20:18.399 --> 00:20:21.149 You can use this function called TryParse 333 00:20:21.149 --> 00:20:29.840 So we bool this and shall we call it success? 334 00:20:29.840 --> 00:20:36.883 If you want to know if it was a success, you can write it like this 335 00:20:36.883 --> 00:20:40.638 So if it was successful 336 00:20:40.638 --> 00:20:48.248 I'll put a condition, say if, and if it succeeds 337 00:20:48.248 --> 00:20:50.098 Like this 338 00:20:50.098 --> 00:20:53.960 Additionally, a value is stored in the number 339 00:20:53.960 --> 00:20:58.347 Right? And you can do something with this number 340 00:20:58.347 --> 00:21:03.577 So I'll wrap it in an if statement like this 341 00:21:03.577 --> 00:21:06.927 Then let's try outputting it first and see if it comes out well 342 00:21:06.927 --> 00:21:10.719 Here, I did the output with Console earlier 343 00:21:10.719 --> 00:21:12.369 With console 344 00:21:12.369 --> 00:21:14.009 Now let's output the number 345 00:21:22.292 --> 00:21:26.120 If you run it 346 00:21:26.120 --> 00:21:30.920 Oh, wait a minute With an else 347 00:21:30.920 --> 00:21:34.915 Let's see if it failed as well 348 00:21:34.915 --> 00:21:38.263 Number conversion failed, I'll write it like this 349 00:21:43.491 --> 00:21:45.991 And the actual number value is 350 00:21:45.991 --> 00:21:48.280 Let me try outputting it as is 351 00:21:48.280 --> 00:21:51.030 If you do this and see the output, 352 00:21:51.030 --> 00:21:54.080 Of course, if you put in numbers, it's like this 353 00:21:54.080 --> 00:21:56.159 The number is 5, so it comes out like this 354 00:21:56.159 --> 00:21:59.394 I'll do this with WriteLine 355 00:22:01.919 --> 00:22:06.841 But if you run it and use an alphabet like this 356 00:22:06.841 --> 00:22:12.527 and press enter, it says conversion failed. It looks like this 357 00:22:12.527 --> 00:22:13.660 This should not number 358 00:22:13.660 --> 00:22:15.877 I need to output inputString 359 00:22:15.877 --> 00:22:18.610 So if you want to see what the actual data is like this 360 00:22:18.610 --> 00:22:22.360 You can output it like this 361 00:22:22.360 --> 00:22:26.119 If you do this, you can see that the conversion has failed 362 00:22:26.119 --> 00:22:30.169 This way, we can now receive only numbers 363 00:22:30.169 --> 00:22:33.219 Then, add a switch case statement here 364 00:22:33.219 --> 00:22:36.546 Let's try branching this once 365 00:22:36.546 --> 00:22:39.999 Write it as switch 366 00:22:40.000 --> 00:22:42.850 Then open the parentheses like this 367 00:22:42.850 --> 00:22:46.728 Then here we have the actual values 368 00:22:46.728 --> 00:22:49.919 Since we are going to branch, we will enter a reference value 369 00:22:49.919 --> 00:22:52.519 Here, this guy called number will be the standard 370 00:22:52.519 --> 00:22:53.919 Enter the number 371 00:22:53.919 --> 00:22:57.474 Then write it like this in parentheses 372 00:22:59.940 --> 00:23:04.390 Switch is written with case 373 00:23:04.390 --> 00:23:06.190 We write case and here 374 00:23:06.190 --> 00:23:10.119 The expected value would be 0 375 00:23:10.119 --> 00:23:13.419 And then after writing 0, at the end, this is called a colon 376 00:23:13.419 --> 00:23:17.470 This is called a colon 377 00:23:17.470 --> 00:23:19.870 This is a semicolon 378 00:23:19.870 --> 00:23:22.559 Can you see it well here? 379 00:23:22.559 --> 00:23:27.909 : If you write it like this, it is a colon 380 00:23:27.909 --> 00:23:30.909 Then like this; but below here 381 00:23:30.909 --> 00:23:35.080 With a comma-shaped thing is called a semicolon 382 00:23:35.080 --> 00:23:38.230 This is what we call it, Colon 383 00:23:38.230 --> 00:23:42.455 Please write a colon like this and then write break 384 00:23:48.984 --> 00:23:52.603 Write it like this 385 00:23:52.603 --> 00:23:57.053 Then we usually do case by case 386 00:23:57.053 --> 00:23:59.603 That's what we say, right? 387 00:23:59.603 --> 00:24:01.503 So when there is a situation 388 00:24:01.503 --> 00:24:04.039 we say it's case by case 389 00:24:04.039 --> 00:24:06.636 Switch too 390 00:24:06.636 --> 00:24:08.539 There can be multiple cases 391 00:24:08.539 --> 00:24:10.989 There is a case where the number is 0 392 00:24:10.989 --> 00:24:13.836 We have 0~2, so we should have 3 393 00:24:13.836 --> 00:24:17.136 So, put in 3 things like this: 0, 1, 2 394 00:24:17.136 --> 00:24:21.440 This one is 1, this one is 2, you could express it like this 395 00:24:21.440 --> 00:24:25.340 If you look closely, you can see that it is a little different from the if statement 396 00:24:25.340 --> 00:24:28.687 For example, if you do this with an if statement, it will be like this 397 00:24:28.687 --> 00:24:32.337 if (number == 0) then do blah blah 398 00:24:32.337 --> 00:24:35.387 Then else if (number == 1) 399 00:24:35.387 --> 00:24:37.559 Something like this and that 400 00:24:37.559 --> 00:24:40.785 And else if (number == 2) 401 00:24:40.785 --> 00:24:43.485 You write it like this 402 00:24:43.485 --> 00:24:47.479 We might accidentally write it like this 403 00:24:47.479 --> 00:24:49.929 The conditions can be entered the same like this 404 00:24:49.929 --> 00:24:53.479 If you do this, the if statement won't throw an error 405 00:24:53.479 --> 00:24:54.880 No error occurs 406 00:24:54.880 --> 00:24:58.180 And in fact this sentence will never come in 407 00:24:58.180 --> 00:25:00.530 Because if it is already true above 408 00:25:00.530 --> 00:25:02.628 it'll go here 409 00:25:02.628 --> 00:25:05.728 Right? If this is false, then this is also false 410 00:25:05.728 --> 00:25:07.978 This one won't come in either, right? 411 00:25:07.978 --> 00:25:10.640 You can make mistakes like this, so 412 00:25:10.640 --> 00:25:14.340 This condition 413 00:25:14.340 --> 00:25:17.040 The value that serves as a basis for creating this conditional expression is 414 00:25:17.040 --> 00:25:19.840 If you use different numbers 415 00:25:19.840 --> 00:25:22.821 standard to divide the criteria like this 416 00:25:22.821 --> 00:25:25.671 If you do it like this with an if statement, you may make some mistakes 417 00:25:25.671 --> 00:25:28.849 So in this case, it is better to use a switch case statement 418 00:25:28.849 --> 00:25:30.280 It's a bit more desirable 419 00:25:30.280 --> 00:25:32.730 Because in the case of a switch case statement, 420 00:25:32.730 --> 00:25:37.030 If these numbers are the same, an error occurs 421 00:25:37.030 --> 00:25:41.070 Iit is impossible to have the same value' 422 00:25:41.070 --> 00:25:45.640 Because it gives an error, 423 00:25:45.640 --> 00:25:49.760 When you divide the value exactly like this, it is better 424 00:25:49.760 --> 00:25:52.049 A switch case statement may be preferable 425 00:25:55.320 --> 00:25:58.120 And in the switch case statement too 426 00:25:58.120 --> 00:26:01.120 There's else statement that we used in the if statement, right? 427 00:26:01.120 --> 00:26:03.341 If it's neither this nor that, right? 428 00:26:03.341 --> 00:26:06.779 If you look here, 'not applicable' 429 00:26:06.779 --> 00:26:09.329 means it doesn't apply here and it doesn't apply here either 430 00:26:09.329 --> 00:26:12.640 It's a neither-or-none situation, right? 431 00:26:12.640 --> 00:26:16.890 So, a situation like that, 432 00:26:16.890 --> 00:26:19.440 That's possible in this switch statement too 433 00:26:19.440 --> 00:26:22.247 Write default here 434 00:26:25.159 --> 00:26:27.474 If you write it like this 435 00:26:30.200 --> 00:26:34.750 what happens then is that this can now be called a jump door 436 00:26:34.750 --> 00:26:37.400 If the value contained here is 0 437 00:26:37.400 --> 00:26:40.729 Here, it goes straight to case 0 438 00:26:40.729 --> 00:26:42.704 Then, if you do something here 439 00:26:42.704 --> 00:26:46.219 After doing this, you meet break, right? 440 00:26:46.219 --> 00:26:48.069 What do you do when you meet a break? 441 00:26:48.069 --> 00:26:50.599 This will escape the switch statement 442 00:26:50.599 --> 00:26:53.549 So that's how it ends, right? 443 00:26:53.549 --> 00:26:55.049 For example, number 1 came in 444 00:26:55.049 --> 00:26:57.549 Then it will go straight here 445 00:26:57.549 --> 00:26:59.193 Then it does something here 446 00:26:59.193 --> 00:27:02.499 and ends after meeting break 447 00:27:02.499 --> 00:27:05.899 This is how it works 448 00:27:05.899 --> 00:27:11.006 So, I'll output it here like this first 449 00:27:11.006 --> 00:27:13.887 Whether the number you entered is 0, 1, or 2 450 00:27:13.887 --> 00:27:15.679 Let me try outputting it 451 00:27:15.679 --> 00:27:18.379 It's called Console, and I'll write down what's here quickly 452 00:27:18.379 --> 00:27:19.822 Let me do that real quick 453 00:27:23.440 --> 00:27:28.718 The number you entered is 0 454 00:27:28.718 --> 00:27:29.902 Write it like this 455 00:27:29.902 --> 00:27:35.041 This would be 1, this would be 2 456 00:27:35.041 --> 00:27:37.441 I don't know what's next here 457 00:27:37.441 --> 00:27:39.441 The number you entered is here 458 00:27:39.441 --> 00:27:42.119 Let's output this number itself 459 00:27:42.119 --> 00:27:45.515 Number is number 460 00:27:50.840 --> 00:27:54.790 But this is now an exception, so I'll put it here 461 00:27:54.790 --> 00:27:59.685 I'll try to express it a bit by using the exclamation mark like this 462 00:27:59.685 --> 00:28:02.935 If you press ctrl+F5, 463 00:28:02.935 --> 00:28:05.559 It asks me to enter a number 464 00:28:05.559 --> 00:28:07.659 Then add 0 here 465 00:28:07.659 --> 00:28:10.695 You can see that number 0 is output properly 466 00:28:14.405 --> 00:28:16.755 Let me try something else, should I press 1? 467 00:28:16.755 --> 00:28:20.555 Then comes here and prints this out 468 00:28:20.555 --> 00:28:22.320 The number you entered is 1 469 00:28:22.320 --> 00:28:25.270 Then if it is not within the range 470 00:28:25.270 --> 00:28:28.370 If we try to write something that is not in the case we wrote 471 00:28:28.370 --> 00:28:31.170 If you put 55 like this 472 00:28:31.170 --> 00:28:33.599 You can see it expressed like this with exclamation marks 473 00:28:33.599 --> 00:28:38.108 towards default 474 00:28:38.108 --> 00:28:41.558 Like this, if statements and switch case statements 475 00:28:41.558 --> 00:28:44.080 are what we've learned so far 476 00:28:44.080 --> 00:28:47.446 This is a very commonly used phrase 477 00:28:47.446 --> 00:28:49.746 Please remember it well 478 00:28:49.746 --> 00:28:52.119 and practice a lot as well 479 00:28:52.119 --> 00:28:55.569 Actually, there are a few more things you can use as conditional statements 480 00:28:55.569 --> 00:28:58.239 There are things like ternary operators and such 481 00:28:58.239 --> 00:29:01.189 Now that we're on the subject, let's try that out for a moment 482 00:29:01.189 --> 00:29:04.256 Let's say there's one more thing, the ternary operator 483 00:29:09.186 --> 00:29:12.236 This is very simple 484 00:29:12.236 --> 00:29:15.424 For example, let's say we have an int number 485 00:29:19.280 --> 00:29:22.530 Let's just input this too 486 00:29:22.530 --> 00:29:24.880 If here, in number 487 00:29:24.880 --> 00:29:28.394 Let's say there is a value of 10 488 00:29:32.146 --> 00:29:35.165 And 489 00:29:39.880 --> 00:29:42.597 Let's say bool type, int? 490 00:29:42.597 --> 00:29:43.980 If there is any number 491 00:29:43.980 --> 00:29:46.280 Depending on the value contained in this number 492 00:29:46.280 --> 00:29:50.560 Let's say there's a part where you want to process some results 493 00:29:50.579 --> 00:29:57.599 For example, if number is even, let's do this 494 00:29:57.599 --> 00:30:07.679 0 if number is even 495 00:30:07.679 --> 00:30:12.502 And if it is odd, it takes the value 1 496 00:30:12.502 --> 00:30:16.520 Let's say I want to create some variables 497 00:30:16.520 --> 00:30:19.440 I'll call this result 498 00:30:19.440 --> 00:30:21.719 The result is 499 00:30:21.719 --> 00:30:27.318 Usually, when expressing even numbers, you can do it like this 500 00:30:27.318 --> 00:30:30.880 Among the operators, there is also something called the remainder operator 501 00:30:30.880 --> 00:30:32.559 There are so many operators 502 00:30:32.559 --> 00:30:34.960 So among the operators, % 503 00:30:34.960 --> 00:30:37.400 There is something called the remainder operator 504 00:30:37.400 --> 00:30:39.239 So what is this? 505 00:30:39.239 --> 00:30:41.799 This is our division operator 506 00:30:41.799 --> 00:30:44.359 Divide, 2 like this 507 00:30:44.359 --> 00:30:48.026 Then, of course, 10/2 will return 5 508 00:30:52.039 --> 00:30:54.182 If you write it like this 509 00:30:54.182 --> 00:30:56.919 This will have the value 5 510 00:30:56.919 --> 00:30:59.200 Let's try verifying it 511 00:30:59.200 --> 00:31:01.836 Let me output it with console 512 00:31:07.410 --> 00:31:09.840 5 is output like this 513 00:31:09.840 --> 00:31:14.919 But this is 11 514 00:31:14.919 --> 00:31:16.799 Then what's the output? 515 00:31:16.799 --> 00:31:18.371 Again, 5 is output 516 00:31:21.559 --> 00:31:23.719 Because this is an integer 517 00:31:23.719 --> 00:31:26.119 it doesn't represent decimal points 518 00:31:26.119 --> 00:31:30.039 Originally, it would be expressed as 5.5, not 5 519 00:31:30.039 --> 00:31:31.350 If this is float 520 00:31:38.359 --> 00:31:39.690 I see, that's because it's number 521 00:31:42.184 --> 00:31:44.679 Because both are integers 522 00:31:44.679 --> 00:31:47.919 2.0 Let's express it like this 523 00:31:47.919 --> 00:31:49.520 Then like this 5.5 524 00:31:49.520 --> 00:31:52.119 You can see that the decimal point is expressed like this 525 00:31:52.119 --> 00:31:55.440 When calculating like this, if you calculate integers and integers, 526 00:31:55.440 --> 00:31:57.119 an integer comes out 527 00:31:57.119 --> 00:32:00.119 Even if the one receiving this is set to float 528 00:32:00.119 --> 00:32:01.799 it can't express decimal points 529 00:32:01.799 --> 00:32:04.719 So either one of them must be a real number 530 00:32:04.719 --> 00:32:07.000 You need to make it a float type 531 00:32:07.000 --> 00:32:09.039 for it to be stored like this 532 00:32:09.039 --> 00:32:14.039 Last time, we talked about it during data types and variables 533 00:32:14.039 --> 00:32:18.440 But if you want to know the remainder of this 534 00:32:18.440 --> 00:32:23.000 Then, you write it like this 535 00:32:23.000 --> 00:32:25.799 When 11 is divided by 2 536 00:32:25.799 --> 00:32:28.280 The remainder is 1 537 00:32:28.280 --> 00:32:30.239 2*5=10, there is a remainder of 1 538 00:32:30.239 --> 00:32:31.799 So if you run it 539 00:32:31.799 --> 00:32:34.400 You can see that 1 is expressed like this 540 00:32:34.400 --> 00:32:35.165 And 541 00:32:39.320 --> 00:32:42.640 if this is 10, then 0 will be expressed 542 00:32:42.640 --> 00:32:45.520 0 will be output like this 543 00:32:45.520 --> 00:32:48.000 There are some remainder operators like this 544 00:32:48.000 --> 00:32:51.637 With this, if it's even, 0, if it's odd, 1 545 00:32:51.637 --> 00:32:52.987 I want to express it like this, but actually this 546 00:32:52.987 --> 00:32:55.039 you can just output this as is 547 00:32:55.039 --> 00:32:56.919 Then let me try it in reverse 548 00:32:56.919 --> 00:32:59.440 1, 0 549 00:32:59.440 --> 00:33:01.280 You might want to do this 550 00:33:01.280 --> 00:33:03.400 Then you can do it like this 551 00:33:03.400 --> 00:33:07.559 ? like this 552 00:33:07.559 --> 00:33:10.719 Then if the result is 0 553 00:33:10.719 --> 00:33:16.080 1:0 You can express it like this 554 00:33:16.080 --> 00:33:19.119 This is called a ternary operator 555 00:33:19.119 --> 00:33:22.599 If you look, ==, based on this 556 00:33:22.599 --> 00:33:26.239 the left and right respectively will be compared 557 00:33:26.239 --> 00:33:29.039 If you do number %2 558 00:33:29.039 --> 00:33:32.159 Since this is 10 now, it's an even number so it will be 0 559 00:33:32.159 --> 00:33:35.640 Then, since 0 and 0 are the same number, they are equal, right? 560 00:33:35.640 --> 00:33:39.559 If they are the same, return the one after the question mark 561 00:33:39.559 --> 00:33:42.159 If this is different, if it's false 562 00:33:42.159 --> 00:33:45.000 The :, colon following this question mark 563 00:33:45.000 --> 00:33:47.960 It returns what is immediately after the colon 564 00:33:47.960 --> 00:33:50.000 These are called ternary operators 565 00:33:50.000 --> 00:33:51.799 This is a ternary operator 566 00:33:51.799 --> 00:33:53.880 Like this ? and : 567 00:33:53.880 --> 00:33:55.000 So there are three terms 568 00:33:55.000 --> 00:33:58.159 One, two, three 569 00:33:58.159 --> 00:34:02.183 It is called a ternary operator because it has three terms 570 00:34:02.183 --> 00:34:03.880 So there are things like this too 571 00:34:03.880 --> 00:34:07.080 when processing conditions 572 00:34:07.080 --> 00:34:08.880 So I'll keep it simple and move on 573 00:34:09.087 --> 00:34:12.829 for Loop, while Loop, Jump Loop, continue and break 574 00:34:13.357 --> 00:34:15.998 Let's try a loop 575 00:34:19.440 --> 00:34:26.200 Repeat statements are usually for statements and while statements 576 00:34:26.200 --> 00:34:27.760 These two are used a lot 577 00:34:27.760 --> 00:34:31.039 There is also do while statement 578 00:34:31.039 --> 00:34:35.520 but it you know while statement, do while statement is pretty simple 579 00:34:35.520 --> 00:34:39.679 So there are two things we're trying to learn 580 00:34:39.679 --> 00:34:41.520 Let's start with for statement 581 00:34:41.520 --> 00:34:43.359 What does a for statement look like? 582 00:34:43.359 --> 00:34:44.479 It's written like this 583 00:34:44.479 --> 00:34:46.760 for 584 00:34:46.760 --> 00:34:49.159 Open the parentheses like this 585 00:34:49.159 --> 00:34:53.840 Next, there are three items that go into this 586 00:34:53.840 --> 00:34:56.760 Put a semicolon here like this 587 00:34:56.760 --> 00:35:00.239 Write two of them like this 588 00:35:00.239 --> 00:35:02.239 Because there are two semicolons 589 00:35:02.239 --> 00:35:07.000 Here are 1, 2, 3 590 00:35:07.000 --> 00:35:08.760 You can put something like this 591 00:35:09.760 --> 00:35:12.679 Then this also has its own area 592 00:35:12.679 --> 00:35:15.479 So this has a scope 593 00:35:15.479 --> 00:35:17.559 Open and close curly brackets 594 00:35:17.559 --> 00:35:19.200 This is what a for statement looks like 595 00:35:19.200 --> 00:35:21.559 Here, I'll express this as number 4 596 00:35:21.559 --> 00:35:25.599 Tasks will go here 597 00:35:25.599 --> 00:35:28.119 So what goes in the first? 598 00:35:28.119 --> 00:35:30.039 This is where initialization comes in 599 00:35:30.039 --> 00:35:33.799 Initial value 600 00:35:33.799 --> 00:35:36.679 You can also declare some variables here 601 00:35:36.679 --> 00:35:41.960 So that's the part that initializes that guy's value 602 00:35:41.960 --> 00:35:44.679 Then what's in the second position? 603 00:35:44.679 --> 00:35:48.039 It's a conditional expression 604 00:35:48.039 --> 00:35:52.359 So if this condition is true, we continue doing this task 605 00:35:52.359 --> 00:35:56.799 If it becomes false, this conditional statement will be escaped 606 00:35:56.799 --> 00:35:59.960 No, not the conditional statement, escape from this loop 607 00:35:59.960 --> 00:36:02.000 It's going to stop 608 00:36:02.000 --> 00:36:10.080 And the third one is the increase and decrease equation 609 00:36:10.080 --> 00:36:12.320 It has this structure 610 00:36:12.320 --> 00:36:16.719 So if you look at this in the order of work 611 00:36:16.719 --> 00:36:19.559 it starts with number 1 612 00:36:19.559 --> 00:36:23.359 Then we check the second, condition expression 613 00:36:23.359 --> 00:36:25.320 Then if this is true 614 00:36:25.320 --> 00:36:27.520 The fourth, the task is done 615 00:36:27.520 --> 00:36:31.679 Then after the fourth one is finished, do the third, increase and decrease expression 616 00:36:31.679 --> 00:36:35.840 Then after the third one is finished, we check the condition again 617 00:36:35.840 --> 00:36:37.719 So the flow is like this 618 00:36:37.719 --> 00:36:39.280 The first one is just one time 619 00:36:39.280 --> 00:36:44.119 From then on, it repeats 2, 4, 3, then 2, 4, 3 again 620 00:36:44.119 --> 00:36:50.320 Here, if the condition is true 621 00:36:50.320 --> 00:36:51.760 it will go here 622 00:36:51.760 --> 00:36:53.719 If true, and if false 623 00:36:53.719 --> 00:36:56.039 It's false 624 00:36:56.039 --> 00:37:00.200 Then escape, it will end 625 00:37:00.200 --> 00:37:03.799 When I say end, I mean end of this for statement 626 00:37:03.799 --> 00:37:06.760 It is structured like this 627 00:37:06.760 --> 00:37:08.959 It's a form that repeats itself 628 00:37:08.959 --> 00:37:15.040 Okay, let's try coding this 629 00:37:15.040 --> 00:37:20.520 A for statement 630 00:37:20.520 --> 00:37:25.319 Let's start from 0 or 1 for simplicity 631 00:37:25.319 --> 00:37:30.680 Let's try an example that prints numbers from 1 to 10 632 00:37:30.680 --> 00:37:35.560 So, first of all, I said that we can put two semicolons here like this 633 00:37:35.560 --> 00:37:38.880 And then we have this area 634 00:37:38.880 --> 00:37:43.079 Then, we can put the initial value in the very first part 635 00:37:43.079 --> 00:37:46.680 I created an integer variable called int i 636 00:37:46.680 --> 00:37:51.000 The default value will be set to 0 637 00:37:51.000 --> 00:37:56.719 Then the second one is until i is less than 10 638 00:37:56.719 --> 00:37:59.640 Then it would be from 0 to 10 639 00:37:59.640 --> 00:38:03.119 I said earlier that I would output numbers from 1 to 10 640 00:38:03.119 --> 00:38:05.599 I think it would be right to do it this way 641 00:38:05.599 --> 00:38:09.520 From 1 to less than or equal to 10 642 00:38:09.520 --> 00:38:12.760 Right? Then it would be from 1 to 10 643 00:38:12.760 --> 00:38:16.599 And you have to increase it one by one to reach 10 644 00:38:16.599 --> 00:38:20.959 If i contains 1, but for i continue to increase 645 00:38:20.959 --> 00:38:24.959 Here, we need to increase i by one in the increment and decrement formula 646 00:38:24.959 --> 00:38:26.382 Then adding i means 647 00:38:26.382 --> 00:38:32.920 It can be expressed like this: i = i + 1 648 00:38:32.920 --> 00:38:36.920 But you can use this a little more conveniently 649 00:38:36.920 --> 00:38:39.400 What this is is 650 00:38:39.400 --> 00:38:42.119 Let's call this int a 651 00:38:42.119 --> 00:38:44.640 If I put 0 in a 652 00:38:44.640 --> 00:38:48.390 Then, increasing a by one means 653 00:38:48.390 --> 00:38:51.000 a = a + 1 654 00:38:51.000 --> 00:38:53.439 But this can be shortened 655 00:38:53.439 --> 00:38:58.040 a++, You can also abbreviate it like this 656 00:38:58.040 --> 00:39:00.040 So, for example, something like this 657 00:39:00.040 --> 00:39:01.880 If you call this professor 658 00:39:01.880 --> 00:39:06.439 This is similar to saying, "prof," in short 659 00:39:06.439 --> 00:39:10.680 So, this ++, this ++ written like this 660 00:39:10.680 --> 00:39:12.959 It's called an increment/decrement operator 661 00:39:12.959 --> 00:39:15.560 There are two types of increment and decrement operators 662 00:39:15.560 --> 00:39:17.400 This is the postfix 663 00:39:17.400 --> 00:39:18.400 There is also a prefix 664 00:39:18.400 --> 00:39:21.280 This can also be written as ++a 665 00:39:21.280 --> 00:39:22.880 What this means is 666 00:39:22.880 --> 00:39:26.560 In the case of a prefix, this is the timing that is added 667 00:39:26.560 --> 00:39:28.640 For example, let me try this 668 00:39:28.640 --> 00:39:30.959 Here 669 00:39:30.959 --> 00:39:33.680 Let's say we do it like this 670 00:39:33.680 --> 00:39:37.760 If I put this in int b 671 00:39:37.760 --> 00:39:39.800 like this 672 00:39:39.800 --> 00:39:41.839 Let me output this 673 00:39:41.839 --> 00:39:49.800 Like this, with console 674 00:39:49.800 --> 00:39:51.199 This is postfix 675 00:39:51.199 --> 00:39:53.640 A prefix is what comes in front 676 00:39:53.640 --> 00:39:55.119 If this is on this side, it's a postfix 677 00:39:55.119 --> 00:39:56.560 I can't use them all at the same time 678 00:39:56.560 --> 00:39:58.040 You need to use one at a time 679 00:39:58.040 --> 00:40:02.705 If you put it in the back and press Ctrl+F5 680 00:40:02.705 --> 00:40:05.405 If you look at it, you can clearly see that a has been increased by one 681 00:40:05.405 --> 00:40:10.080 I thought I had it, but I can see that it outputs 0 682 00:40:10.080 --> 00:40:14.030 Right? What this mean is, when you use a postfix 683 00:40:14.030 --> 00:40:18.030 This semicolon, this one line, after it is executed 684 00:40:18.030 --> 00:40:23.600 When moving down to the next line, a increases to 1 685 00:40:23.600 --> 00:40:28.700 So, the order of the assignment operator = is 686 00:40:28.700 --> 00:40:34.320 First, put a into b, and then increase a 687 00:40:34.320 --> 00:40:37.920 So it contains 0, because a originally contained 0 688 00:40:37.920 --> 00:40:41.670 This is one of the increment/decrement operators that is in the postfix form 689 00:40:41.670 --> 00:40:44.160 What happens if you change this to a prefix? 690 00:40:44.160 --> 00:40:46.360 First, increase a by 1 691 00:40:46.360 --> 00:40:50.310 Then, the value of a is stored in b using the assignment operator = 692 00:40:50.310 --> 00:40:52.320 Then, of course, 1 will be contained in b 693 00:40:52.320 --> 00:40:56.520 If you run it, you can see that it contains 1 694 00:40:56.520 --> 00:41:00.080 So when you use this increment/decrement operator 695 00:41:00.080 --> 00:41:04.030 Depending on whether you write this on the left or right side of ++ 696 00:41:04.030 --> 00:41:07.680 There are some differences, so I think it would be good to remember them well 697 00:41:07.680 --> 00:41:11.080 So it's like this, it can be written like this 698 00:41:11.080 --> 00:41:13.380 but it can also be written like this 699 00:41:13.380 --> 00:41:15.280 Of course, it's alone here now 700 00:41:15.280 --> 00:41:17.360 so it doesn't matter if you just write it like this 701 00:41:17.360 --> 00:41:21.560 But usually, almost like a habit 702 00:41:21.560 --> 00:41:23.360 It is often written like this 703 00:41:23.360 --> 00:41:26.639 I'll output it 704 00:41:26.639 --> 00:41:33.559 If you output Console.WriteLine(i) 705 00:41:33.559 --> 00:41:36.359 You can see that it outputs out numbers from 1 to 10 706 00:41:36.359 --> 00:41:41.209 Here, the for statement meets this conditional expression 707 00:41:41.209 --> 00:41:44.000 If it's true, I'll keep doing this 708 00:41:44.000 --> 00:41:47.984 Then do this, increase it, and compare again 709 00:41:47.984 --> 00:41:50.134 Do this, increase it, and compare it again 710 00:41:50.134 --> 00:41:52.823 It keeps repeating this 711 00:41:52.823 --> 00:41:56.273 So the moment this becomes false, it stop doing the work 712 00:41:56.273 --> 00:42:00.959 It escapes the for loop right away 713 00:42:00.959 --> 00:42:04.109 But usually, when you use something like a for loop 714 00:42:04.109 --> 00:42:08.160 Things that are used together a lot, such as arrays 715 00:42:08.160 --> 00:42:12.017 There are several, for example these args 716 00:42:12.017 --> 00:42:14.817 When we first did this, we put some values ​​here 717 00:42:14.817 --> 00:42:16.119 and you can output that too 718 00:42:16.119 --> 00:42:18.819 For example, if I want to output this, 719 00:42:18.819 --> 00:42:25.039 You can also write it like this here, writing for 720 00:42:25.039 --> 00:42:29.239 The array starts from 0 721 00:42:29.239 --> 00:42:32.960 This is called a subscript, an index 722 00:42:32.960 --> 00:42:36.060 So, I write it like this, like this 723 00:42:36.060 --> 00:42:38.260 This is how you write it 724 00:42:38.260 --> 00:42:40.880 When writing a for loop, you can do it like this 725 00:42:40.880 --> 00:42:47.630 int i=0; i< args.Length; 726 00:42:47.630 --> 00:42:50.080 You can express it like this 727 00:42:50.080 --> 00:42:55.440 Then output the ith value of args 728 00:42:56.440 --> 00:43:01.408 You can mix it like this 729 00:43:01.408 --> 00:43:05.158 Loops are often used with arrays like this 730 00:43:05.158 --> 00:43:10.308 Now, we search by increasing the array's subscript number by one 731 00:43:10.308 --> 00:43:14.420 It is used a lot because these things can be done 732 00:43:14.440 --> 00:43:17.740 What is an array? As I explain, things keep coming up 733 00:43:17.740 --> 00:43:22.679 An array is a variable that contains some data 734 00:43:22.679 --> 00:43:27.919 It is a variable, but it is a variable contained in a continuous space 735 00:43:27.919 --> 00:43:29.969 Yeah, that's why it's like this 736 00:43:29.969 --> 00:43:32.440 Just briefly remember what it is 737 00:43:32.440 --> 00:43:35.965 I'll try one of these 738 00:43:35.965 --> 00:43:39.240 I want to output only even numbers. I can do something like this 739 00:43:39.240 --> 00:43:43.390 There are many cases where formulas are created and processed like this 740 00:43:43.390 --> 00:43:45.796 So let's try outputting only even numbers 741 00:43:48.974 --> 00:43:51.174 If you do this, you can do this 742 00:43:51.174 --> 00:43:55.224 If i is even 743 00:43:55.224 --> 00:43:57.960 But earlier, when we were doing the ternary operator 744 00:43:57.960 --> 00:44:01.660 To handle an even number, we did this 745 00:44:01.660 --> 00:44:05.399 I did it using the remainder operator, the % operator 746 00:44:05.399 --> 00:44:10.349 You can do the same thing, if you do i % 2 747 00:44:10.349 --> 00:44:15.520 If the result is 0, it is even, and if it is 1, it is odd 748 00:44:15.520 --> 00:44:17.970 Right? Using this principle 749 00:44:17.970 --> 00:44:21.120 I want to multiply by 3, also in that case 750 00:44:21.120 --> 00:44:23.440 You can just divide it by 3 751 00:44:23.440 --> 00:44:28.090 So if it's 0 when divided by 3, it's a multiple of 3 752 00:44:28.090 --> 00:44:29.920 You can do it like this 753 00:44:29.920 --> 00:44:32.820 I want to output only even numbers 754 00:44:32.820 --> 00:44:36.524 I'll try writing it like this 755 00:44:36.524 --> 00:44:39.824 And actually, if you don't put use curly brackets 756 00:44:39.824 --> 00:44:44.600 What happens if you don't use curly brackets? If you do this with an if statement 757 00:44:44.600 --> 00:44:51.112 If you see a semicolon like this after parentheses like this, 758 00:44:51.112 --> 00:44:52.279 This sentence ends 759 00:44:52.279 --> 00:44:56.935 So, if you want to omit the curly brackets in the if statement 760 00:44:59.839 --> 00:45:03.165 If you want to omit the curly brackets like this, 761 00:45:05.519 --> 00:45:08.119 You can just write it like this 762 00:45:08.119 --> 00:45:11.969 This is a coding style 763 00:45:11.969 --> 00:45:16.279 Side effects? Those problems can arise 764 00:45:16.279 --> 00:45:19.929 For example, if you accidentally write something like this 765 00:45:19.929 --> 00:45:22.779 Then, as I mentioned earlier, this if statement 766 00:45:22.779 --> 00:45:26.519 It ends when you meet this semicolon 767 00:45:26.519 --> 00:45:30.469 Then if we write like this, the Console.WriteLine(i) part 768 00:45:30.469 --> 00:45:34.279 You might think it belongs inside an if statement, but it doesn't 769 00:45:34.279 --> 00:45:36.179 So you might make a lot of mistakes 770 00:45:36.179 --> 00:45:39.379 So, if possible, use curly brackets like this 771 00:45:39.379 --> 00:45:42.629 By creating a scope like this, even one line 772 00:45:42.629 --> 00:45:46.640 I recommend writing it like this 773 00:45:46.640 --> 00:45:50.679 I'll try outputting only even numbers like this 774 00:45:52.559 --> 00:45:56.839 Then you can see that only even numbers are output 775 00:45:56.959 --> 00:46:01.359 Then, let's try writing this using a while loop 776 00:46:01.359 --> 00:46:04.120 The for loop is written like this, but how do you write a while loop? 777 00:46:04.120 --> 00:46:08.559 It's simpler, type while 778 00:46:08.559 --> 00:46:12.109 Then, open the parentheses here like this 779 00:46:12.109 --> 00:46:14.839 Then create a scope 780 00:46:14.839 --> 00:46:17.177 You can write it like this 781 00:46:17.177 --> 00:46:21.079 If this condition is true, continue doing this 782 00:46:21.079 --> 00:46:24.626 I'm going to keep doing this until it turns out to be false 783 00:46:24.626 --> 00:46:26.440 It's much simpler 784 00:46:26.440 --> 00:46:29.790 So if you do it like this above 785 00:46:29.790 --> 00:46:34.399 Let's create something called int j 786 00:46:34.399 --> 00:46:36.617 Set it to 0 and j 787 00:46:39.079 --> 00:46:40.179 Should I do the same as above? 788 00:46:40.179 --> 00:46:45.160 You can configure it like this from 1 to 10 789 00:46:45.160 --> 00:46:47.640 And here we increase j by one 790 00:46:50.616 --> 00:46:55.119 In a way, the principle is exactly the same 791 00:46:55.119 --> 00:46:58.619 But a while loop is a bit more dangerous than for loop 792 00:46:58.619 --> 00:47:01.600 There is also a chance that it will fall into an infinite loop 793 00:47:01.600 --> 00:47:04.800 For example, this is usually written like this 794 00:47:04.800 --> 00:47:07.239 but it's also written like this a lot 795 00:47:07.239 --> 00:47:09.589 Set this to true 796 00:47:09.589 --> 00:47:13.720 Here, with an if statement, for example if j does something 797 00:47:13.720 --> 00:47:19.300 Stop repeating this and stop now 798 00:47:19.300 --> 00:47:21.599 There are many configurations like this as well 799 00:47:21.599 --> 00:47:24.749 If this condition is not met the while loop 800 00:47:24.749 --> 00:47:28.440 could keep spinning infinitely 801 00:47:28.440 --> 00:47:32.190 So, you have to be a little careful when writing while loops 802 00:47:32.190 --> 00:47:34.631 First, let's try writing it the same way 803 00:47:36.829 --> 00:47:41.920 Let's output only the even numbers like this. In the same way 804 00:47:41.920 --> 00:47:43.339 I guess you could write it like this 805 00:47:51.636 --> 00:47:54.113 Let me just leave this as a comment for now 806 00:48:01.239 --> 00:48:05.197 You can see that only even numbers are output 807 00:48:09.880 --> 00:48:14.030 If you look at it, it's not that difficult, right? 808 00:48:14.030 --> 00:48:18.839 And besides while, there is also something called do while 809 00:48:18.839 --> 00:48:22.239 Put do {} 810 00:48:22.239 --> 00:48:25.519 Then at the end, write while(); like this: 811 00:48:25.519 --> 00:48:27.201 And here the conditions go like this 812 00:48:27.201 --> 00:48:29.760 You can do it like this with a semicolon 813 00:48:29.760 --> 00:48:35.159 It's like this, and if you write it exactly the same way, it will be like this 814 00:48:35.159 --> 00:48:38.359 It's like this, and this content 815 00:48:38.359 --> 00:48:41.080 will go in here 816 00:48:41.080 --> 00:48:43.530 Actually, the difference between while and do while is 817 00:48:43.530 --> 00:48:45.230 while loop, if a condition 818 00:48:45.230 --> 00:48:47.760 If it doesn't become true even once 819 00:48:47.760 --> 00:48:50.160 If this isn't true when you first start out 820 00:48:50.160 --> 00:48:52.360 it doesn't do all this at all 821 00:48:52.360 --> 00:48:54.640 And it ends right away 822 00:48:54.640 --> 00:48:58.240 But do while does this once, then 823 00:48:58.240 --> 00:48:59.840 Then checks this 824 00:48:59.840 --> 00:49:02.940 And if that's true, then we go back up and do this 825 00:49:02.940 --> 00:49:06.520 So do while unconditionally does what is here once 826 00:49:06.520 --> 00:49:11.431 There is a difference that it then checks the conditions 827 00:49:11.431 --> 00:49:16.919 So, these are things that you need when you are coding 828 00:49:16.919 --> 00:49:20.319 There are times when you want to handle it like this 829 00:49:20.319 --> 00:49:23.719 In that case, you can use the do while loop 830 00:49:23.719 --> 00:49:25.819 Usually, just a while loop is enough 831 00:49:25.819 --> 00:49:28.200 Most of the writing is possible 832 00:49:28.200 --> 00:49:33.280 So I'll just keep this simple and move on 833 00:49:33.280 --> 00:49:39.299 Now finally, there is something called a jump statement 834 00:49:39.299 --> 00:49:41.449 Then, with the existing for loop 835 00:49:41.449 --> 00:49:44.870 I'll try making a jump statement at last 836 00:49:44.880 --> 00:49:47.730 What is a jump statement? 837 00:49:47.730 --> 00:49:51.230 It determines whether 838 00:49:51.230 --> 00:49:55.440 it will continue the repetition 839 00:49:55.440 --> 00:49:59.090 or it will go straight to the increment/decrement expression 840 00:49:59.090 --> 00:50:00.760 without doing the {} task 841 00:50:00.760 --> 00:50:03.210 Or if there were some conditions here 842 00:50:03.210 --> 00:50:07.710 End this loop right away without going up to the conditional expression 843 00:50:07.710 --> 00:50:09.719 You can also process it like this 844 00:50:09.719 --> 00:50:14.169 So let's first look at the concept of skipping 845 00:50:14.169 --> 00:50:15.819 Actually, there are two keywords 846 00:50:15.819 --> 00:50:18.359 One is continue 847 00:50:18.359 --> 00:50:20.359 The other one is called break 848 00:50:20.359 --> 00:50:23.640 Earlier, we used break briefly when doing a switch case statement 849 00:50:23.640 --> 00:50:26.040 The guy called break is 850 00:50:26.040 --> 00:50:29.280 ending the sentence right away 851 00:50:29.280 --> 00:50:32.280 It means to brake, to stop 852 00:50:32.280 --> 00:50:37.559 And continue is the concept of continuing 853 00:50:37.559 --> 00:50:39.909 So if you want to output only even numbers 854 00:50:39.909 --> 00:50:43.360 You can also write it like this 855 00:50:43.360 --> 00:50:48.060 Write this outside the if statement like this 856 00:50:48.060 --> 00:50:50.260 Then, I want to do only even numbers in the conditional expression 857 00:50:50.260 --> 00:50:52.599 So, if it's an odd number, 858 00:50:52.599 --> 00:51:01.271 This in other words, if it's an odd number, 859 00:51:01.271 --> 00:51:04.447 I want to skip 860 00:51:04.447 --> 00:51:07.497 You might want to do this 861 00:51:07.497 --> 00:51:11.880 So, to express this as an odd number, you do it like this 862 00:51:11.880 --> 00:51:15.880 If the remainder when this value i is divided by 2 is 1, then it is an odd number 863 00:51:15.880 --> 00:51:22.293 In that case, write continue here 864 00:51:22.293 --> 00:51:25.793 So, what happens when you encounter continue? 865 00:51:25.793 --> 00:51:29.043 At first, 1 is put into i 866 00:51:29.043 --> 00:51:32.359 Then we ask if i is less than 10, which is true 867 00:51:32.359 --> 00:51:35.209 Then it comes down, and it's 1 868 00:51:35.209 --> 00:51:38.840 Then it will be caught here, it will be caught in the conditional statement and it will be true 869 00:51:38.840 --> 00:51:41.740 Right? Because 1 divided by 2 has a remainder of 1 870 00:51:41.740 --> 00:51:43.890 Then you will come across continue 871 00:51:43.890 --> 00:51:46.840 When you meet continue, you don't come down here 872 00:51:46.840 --> 00:51:49.290 From here, it goes straight to the increment/decremet expression 873 00:51:49.290 --> 00:51:52.087 So we do this and increase by one 874 00:51:52.087 --> 00:51:54.159 Check the conditions again and come down 875 00:51:54.159 --> 00:51:57.609 Then, since i increased by 1, it would have changed from 1 to 2 876 00:51:57.609 --> 00:52:02.759 If the value is then 2, divided by 2, the remainder is 0 877 00:52:02.759 --> 00:52:04.159 So it doesn't get caught here 878 00:52:04.159 --> 00:52:06.759 Then this is output 879 00:52:06.759 --> 00:52:10.459 It goes round and round like this and ends when it meets the conditions here 880 00:52:10.459 --> 00:52:14.359 We can work with that syntax by changing it 881 00:52:14.359 --> 00:52:16.209 Let's run it again 882 00:52:16.209 --> 00:52:18.909 As you can see, only even numbers are output 883 00:52:18.909 --> 00:52:25.320 The existing method, the existing method was done like this, with this syntax 884 00:52:25.320 --> 00:52:27.370 This is outputting it only when it is 0 885 00:52:27.370 --> 00:52:31.022 The difference in the way continue is used is 886 00:52:31.022 --> 00:52:33.122 Actually there is no big difference 887 00:52:33.122 --> 00:52:37.520 But when we code, readability improves a lot 888 00:52:37.520 --> 00:52:43.139 What I mean is, in fact, this conditional statement 889 00:52:43.139 --> 00:52:47.539 If you do it this way to get in, right? 890 00:52:47.539 --> 00:52:50.487 When i is 5, you may not want to do this at all 891 00:52:50.487 --> 00:52:57.943 I don't want to do if (i==5) 892 00:52:57.943 --> 00:53:01.293 If you want to do it this way, you don't actually have to use continue like this 893 00:53:01.293 --> 00:53:06.960 If you coded it like this, you should do it like this 894 00:53:06.960 --> 00:53:13.840 && i != 5, You have to write it like this 895 00:53:13.840 --> 00:53:16.340 And so it becomes an intersection 896 00:53:16.340 --> 00:53:21.090 It's like this: output only when i is even and i is not 5 897 00:53:21.090 --> 00:53:24.340 If you write down the conditions in this way 898 00:53:24.340 --> 00:53:28.247 This is where it gets really complicated and later on when we read it 899 00:53:28.247 --> 00:53:31.947 When I read the code, I go, what does this mean? 900 00:53:31.947 --> 00:53:36.200 There are some drawbacks that require a lot of looking into 901 00:53:36.200 --> 00:53:40.950 So these things 902 00:53:40.950 --> 00:53:44.244 If you use something like continue, it becomes very convenient 903 00:53:47.559 --> 00:53:49.252 This is how you write it 904 00:53:53.453 --> 00:53:56.772 then 905 00:53:56.772 --> 00:53:59.372 First, it filters out all the continue above 906 00:53:59.372 --> 00:54:02.377 When i is not 5, no, when i is 5 907 00:54:02.377 --> 00:54:05.919 When i is 5, skip it 908 00:54:05.919 --> 00:54:08.269 Then skip the odd numbers of i 909 00:54:08.269 --> 00:54:11.719 And just output the rest 910 00:54:11.719 --> 00:54:15.117 Right? Then below, I actually 911 00:54:15.117 --> 00:54:17.667 Just do the work you want to do 912 00:54:17.667 --> 00:54:20.880 You can filter everything from above 913 00:54:20.880 --> 00:54:25.130 Right? So if you write it like this, it would be a bit easier 914 00:54:25.130 --> 00:54:28.799 This makes it easier to read the code 915 00:54:28.799 --> 00:54:31.599 And finally, there's this guy called break 916 00:54:31.599 --> 00:54:34.999 I want to break, randomly, I'll say 917 00:54:34.999 --> 00:54:39.119 If it's 9, stop 918 00:54:39.119 --> 00:54:44.773 I want to perform a command like that 919 00:54:49.158 --> 00:54:57.583 If i is 9, I want to stop the loop 920 00:54:57.583 --> 00:55:00.960 You can do it like this 921 00:55:00.960 --> 00:55:03.010 So here you can write like this 922 00:55:03.010 --> 00:55:08.310 if (i == 9) { break; } 923 00:55:08.310 --> 00:55:11.119 You can write it like this 924 00:55:11.119 --> 00:55:14.119 Let's give it a try 925 00:55:14.119 --> 00:55:16.969 Then, originally, it was output up to 10 926 00:55:16.969 --> 00:55:21.359 Because there is a break at 9, there is no more repetition 927 00:55:21.359 --> 00:55:22.709 It can't reach 10 928 00:55:22.709 --> 00:55:25.659 So it can't output 10, right? 929 00:55:25.659 --> 00:55:27.659 Because the moment you meet 9, you get out 930 00:55:27.659 --> 00:55:30.400 Originally it went from 9 to 10 931 00:55:30.400 --> 00:55:33.299 and output up to 10 932 00:55:33.299 --> 00:55:35.400 Then this loop ended 933 00:55:35.400 --> 00:55:39.760 Because I ended it with break right away when i was 9 934 00:55:39.760 --> 00:55:42.910 So it can't output 10 935 00:55:42.910 --> 00:55:46.595 Now, let's summarize what we learned in this unit 936 00:55:47.234 --> 00:55:48.184 if statement, switch statement Control statement Used to control the flow of the program 937 00:55:48.184 --> 00:55:49.134 Conditional statement if statement If the condition is true, execute {}; If false, terminate {} 938 00:55:49.134 --> 00:55:50.134 Switch statement Allows multiple cases Errors occur with duplicate values, so it’s used for exact value branching 939 00:55:50.134 --> 00:55:51.134 Ternary operator An operator with three terms A structure that outputs 1 if number is even, 0 if number is odd int number=10; float a=number%2==0?1:0; 940 00:55:51.134 --> 00:55:52.085 If the values ​​are equal, return the value following the question mark and if they are different, return the value following the question mark colon 941 00:55:52.085 --> 00:55:53.335 Comparison Operators and Logical Operators Comparison Operators A==B True if A and B are equal A!=B True if A and B are different 942 00:55:53.335 --> 00:55:54.585 True if A>BA is greater than B True if A=BA is greater than or equal to B True if A<=BA is less than or equal to B 943 00:55:54.585 --> 00:55:55.835 True if both logical operators A&&BA and B are true, otherwise false 944 00:55:55.835 --> 00:55:57.104 True if either A||BA,B is true, otherwise false False if AA is true, true if false 945 00:55:57.104 --> 00:55:58.004 for loop, while loop, jump statement continue and break Iteration statement for loop If the condition is true, {} is repeated, and if false, the loop is terminated 946 00:55:58.004 --> 00:55:58.804 Structure: for(initial value; condition; increment/decrement expression) {to-do} 947 00:55:58.804 --> 00:55:59.554 while loop Repeats {} until the condition is false Be careful because there is a chance of falling into an infinite loop 948 00:55:59.554 --> 00:56:00.354 Depending on the situation, a do while statement is sometimes used, which checks the if statement after performing {} once 949 00:56:00.354 --> 00:56:01.154 Jump statement Determines whether to continue the loop or send it in incremental order without {} break: Used to arbitrarily end the loop 950 00:56:01.154 --> 00:56:01.962 Continue with the continue statement. When continue is encountered, it immediately moves to the increment expression of the for loop.