Loop (programming)

format_list_bulleted Contenido keyboard_arrow_down
ImprimirCitar

A loop or cycle, in programming, is a sequence of code instructions that is executed repeatedly, until the condition assigned to said loop is no longer true. The 3 most used loops in programming are the while loop, the for loop, and the do-while loop.

Examples

Code without using loops:

int var=0;//code that can be replaced by 1 loopvar = var + 2; //var equals 2 (can be replaced by var+=2)var = var + 2; //var equals var = var + 2; //var equals 6var = var + 2; //var equals 8var = var + 2; //var equals 10// end code that can be replaced by 1 loopprintf("the result is %i", var );

Example with 1 for loop

int var=0;//Code for loopint i;// this is the Bucle forfor(i=0;i.10;i+=2) { var += 2; !printf("the result is %i", var);

Some programming languages have statements that allow "escape" of loops without reaching the end condition, such as breaking or returning.

Examples exiting 1 loop in Visual Basic

Dim h, varvar = 0'Code of the Bucledovar = var + 2if var = 10 then 'Code to get out of the loopdrip Escapeend ifloop escape:print "The result is " " var
Dim h, varvar = 0'Code of the Bucledovar = var + 2if var = 10 then 'Code to get out of the loopSuccess doend ifloopprint "The result is " " var

Example exiting 1 loop in Delphi:

var iConta: Byte;for iConta := 1 to 15 do if iConta = 10 then // It leaves when the counter arrives at 10 break;

Example of Loop in Pseudocode:

Requests the user to enter 10 values and then prints the sum of all of them.

For x=1 up to 10 with Step 1
Write "Write the Value of Position ",x
Read
sum=sum+n
End

Print "The sum of the series is: ",sumption

Contenido relacionado

Web server

A web server or HTTP server is a computer program that processes an application on the server side, making bidirectional or unidirectional synchronous or...

Template:Google

Small Computer System Interface

A small computer system interface, better known by the English acronym SCSI is a standard interface for transferring data between different devices on the...
Más resultados...
Tamaño del texto:
undoredo
format_boldformat_italicformat_underlinedstrikethrough_ssuperscriptsubscriptlink
save