5.5 Switch

Hello everyone, in the previous video, we talked about the use of the "switch" instruction. In this video. We’re going to talk about the for loop. But first, what is a loop? In programming, a loop is a technique that allows you to repeat one or more instructions without having to retake the same set of instructions several times. There are different types of loops. A “for” loop is the one that runs for a predefined number of times. A “while” loop repeats for as long as the expression is true. A «do while» loop or a repetition is the one that repeats until an expression becomes false.Now, we will open our intellij, then we will see the first loop which is the for loop, so right away. So here we will make an example of a for loop, which repeats an instruction five times. for In parentheses int i = 0 semicolon i < 5 semicolon i ++ Here it is an "initialization" it is an expression that initializes the loop. It usually declares and assigns an iterator. Termination is an expression that is evaluated before each loop execution. If it is rated on false, the loop stops. An increment is an expression that is evaluated each time an iteration is performed Now, we will display "Hello" five times And as we can see. The equivalent code without using a loop is Can you imagine if we wanted to say Hello not 5, but 50 or 100 times? That’s why loops are useful in this context Another example would be to display the number from 0 to 10 for example. for in parentheses int i = 0 i <= 10 i++ We display "i" You can make loops that instead of incrementing the variable, decremente, watch I go back therefore from 10 I say that as long as i >= 0 i - - That was all for the video In the next video, We’ll do two small exercises, on the loop for It’s really simple, don’t worry Go to the next one!