Course C Initial 16th - Loop For Part 1


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 decrement)’ this variable is known only inside for.

In the next lesson, we’ll see the part 2 of this command use. Practice what we have seen here.

Well, that’s all folks!
See you later!
 

Comentários

More Famous Posts

Course C Initial 7th – Training with Math

Course C Initial – 3rd Variables Part. 1

Course Python For Life 3 – Input Command