Algorithm Programming - Repetition
REPETITION
As a programmer when writing a program you may encounter problems where you need to run a block several number of times. Generally, programs run codes in order from top to bottom or sequentially; first line then second line and so on, this is where Repetition shines the brightestWhat is a repetition?
Repetition also known as looping is a type of function that repeats a single or more block of codes several number of times. To simplify it we could also say repetition in programming is the same as things we do in our daily routine e.g eating, showering etc.There are 4 kinds of repetition:
1. For
2. While
3. Do...While
4. Nested loop
What we'll be learning this time is For loop.
What is For loop?
For is used for repeating certain tasks in a specific number of times.the structure of For is as follows.
For(initialization; condition; increment or decrement){
statement(s);
}
initialization is a single declaration and executed first.
condition is a switch that controls whether the statement(s) 'True' or 'False'.
increment or decrement is a statement that keeps the initialization updated through the whole process.
*do note that all three of the statements are optional and the end results may vary.
Comments
Post a Comment