Monday, October 29, 2018

Repetition

What is repetition?
Repetition means repeating the sequence of instructions several times, or until certain results are achieved. In programming terms, this means loops of all types, such as repetitive, for, while, etc.




How is repetition used? 

There are 3 operations for repetition:

  1. for
  2. while
  3. do-while
For

for ( variable initialization; condition; variable update ) {
  Code to execute while the condition is true
}


Variable initialization allows you to declare variables and assign values or assign values to existing variables. Second, the condition tells the program that while the correct conditional expression of the loop must be repeated. The variable update section is the easiest way to loop to handle variable changes.

While

while ( condition ) { Code to execute while the condition is true } 
The true represents a boolean expression

Do-While
do{< statements >;}while(exp);
While and Do-While is similar. The difference will be do-while will run the statements at least once regardless the while expression, while While will run if the condition is true.


Importance of repetition

One of the most basic but useful tasks of programming is to have a code block run multiple times - many programs or Web sites that produce extremely complex output (such as a message board) do not execute. in fact, a task several times.







By :Steven
2201852132
Computer Science and Statistics




No comments:

Post a Comment