大象传媒

Algorithms - EdexcelIteration

Algorithms are step-by-step plans for solving problems. Algorithms can be designed using pseudo-code, flowcharts, written descriptions and program code. There are also some standard algorithms for searching and sorting.

Part of Computer SciencePrinciples of computer science

Iteration

is the third programming construct. There are times when a needs to repeat certain steps until told otherwise, or until a condition has been met. This process is known as iteration.

Iteration is also often referred to as looping, since the program 鈥榣oops鈥 back to an earlier line of code. Sections of code that are iterated are called loops.

Iteration enables programmers to greatly simplify a program. Instead of writing out the same lines of code again and again, a programmer can write a section of code once, and ask the program to execute it again and again until it is no longer needed.

An explanation of iteration, as used in algorithms and programming

This program prints a message out six times:

SEND 鈥楥oding is cool鈥 TO DISPLAY
                    SEND 鈥楥oding is cool鈥 TO DISPLAY
                    SEND 鈥楥oding is cool鈥 TO DISPLAY
                    SEND 鈥楥oding is cool鈥 TO DISPLAY
                    SEND 鈥楥oding is cool鈥 TO DISPLAY
                    SEND 鈥楥oding is cool鈥 TO DISPLAY