Postagens

Mostrando postagens com o rótulo For

Course C Initial 17th - Loop FOR Part 2

Imagem
Now, I have others notes about loop for. This command can be used like while, but it structure is different because the loop for use ‘;’. Below, see the basic structure of For command.   Between ‘;’, you put a condition and so, the command will work like a loop while. So, it works with this: a variable; a condition; a increment or decrement. The command FOR is a good tool that will be used many times. But if you ask to me: What’s the difference between this command and the command do while or while? My answer is that the command for is universal, but do-while is a special case that in others languages, there’s not, python is an example. FOR works with conditions too, but it allow to us, work with a limited possibility. Look at this image: The image give us it explanation. But I have a note: the last value of a is 11, but 11 isn’t large than 10, that’s the reason of the code stop. Below, see it being ran. The ...

Course C Initial 16th - Loop For Part 1

Imagem
As promised in previous lesson, I present for you the Loop For. It has something different of Do while or while. It works with a condition and increments. It structure is here below. Another words, the commands will be ran up to the condition be False, generally when the increment or decrement happens and the condition become False, else it repeat. You can use more than a condition in your code if you desire, it depends of context. Below see an example of a loop for.   In this case, it doesn’t run the code because 20 is larger than 0, 20>0. If you change it for ‘a>=0’, so the condition is true up to a=-1. Make yourself! As we can see, we can create a variable outside for, but we can create it inside for too. In this case, the variable called a is known in all main function. Outside, a is unknown. Note: if you create a variable inside for, ‘for(type variable=0; condition; increment or decre...