Loop structures: Difference between revisions

From Rosetta Code
Content added Content deleted
(Added C++)
(Added Pascal)
Line 80: Line 80:
} while ( condition );
} while ( condition );
}
}

==[[Pascal]]==
[[Category:Pascal]]

===while===

'''Compiler:''' [[Turbo Pascal]] 7.0

WHILE condition1 DO
BEGIN
procedure1;
procedure2;
END;

===repeat-until===

'''Compiler:''' [[Turbo Pascal]] 7.0
REPEAT
procedure1;
procedure2;
UNTIL condition1;

===for===

'''Compiler:''' [[Turbo Pascal]] 7.0

FOR counter=1 TO 10 DO
BEGIN
procedure1;
procedure2;
END;

Revision as of 16:29, 25 January 2007

AppleScript

repeat-until

set i to 5
repeat until i is less than 0
	set i to i - 1
end repeat
repeat
	--endless loop
end repeat

C

while

Compiler: GCC 4.1.2

int main (int argc, char ** argv) {
  int condition = 1;

  while ( condition ) {
    // Do something
    // Don't forget to change the value of condition.
    // If it remains nonzero, we'll have an infinite loop.
  }
}

C++

Run-Time Control Structures

for

Compiler: GCC 3.3.4

#include <iostream>

int main()
{
 int i = 1;

 // Loops forever:
 for(; i == 1;)
  std::cout << "Hello, World!\n";
}

do-while

Compiler: GCC 4.1.2

int main (void) {
  int condition = 1;

  do {
    // Do something
    // Don't forget to change the value of condition.
    // If it remains nonzero, we'll have an infinite loop.
  } while ( condition );
}

Run-Time Control Structures

while

Compiler: GCC 4.1.2

int main (void) {
  int condition = 1;

  while ( condition ) {
    // Do something
    // Don't forget to change the value of condition.
    // If it remains nonzero, we'll have an infinite loop.
  }
}

do-while

Compiler: GCC 4.1.2

int main (void) {
 int condition = 1;

 do {
   // Do something
   // Don't forget to change the value of condition.
   // If it remains nonzero, we'll have an infinite loop.
 } while ( condition );
}

Pascal

while

Compiler: Turbo Pascal 7.0

 WHILE condition1 DO
   BEGIN
     procedure1;
     procedure2;
   END;

repeat-until

Compiler: Turbo Pascal 7.0

 REPEAT
   procedure1;
   procedure2;
 UNTIL condition1;

for

Compiler: Turbo Pascal 7.0

 FOR counter=1 TO 10 DO
   BEGIN
     procedure1;
     procedure2;
   END;