Programming & Algorithm Loop Statements August 07, 2006
Array: The Basic An Array is an indexed group of data storage that have the same name and are distinguished from each other by an index (that is a number following the variable name, enclosed in brackets). A single-dimensional array declaration has the following form: typename array_name[size]; Note : The  first index  of an array is  zero .
Loop Statement The function is to execute one/some statement(s) several times. There are three loop statements: for statement while…do statement do…while statement
The  for S tatement Syntax: for ( initial ;  condition ;  increment ) statement(s);
The  for S tatement E.g.: Display the words  “Welcome to this cruel world..”  ten times. for (i ← 0; i ≤ 9; i ← i + 1) output(“Welcome to this cruel world..”)
Exercises Create an algorithm that displays numbers (1 to 25) on screen. Create an algorithm that uses loop statements to displays following formation of ‘*’ character on screen. a. b. c.
Exercises Create an algorithm that prints the result of X powered by Y. The algorithm received two numbers of integer (X and Y). Create an algorithm that asks one number of integer (N) and displays the numbers of Fibonacci on screen. E.g.: 1 1 2 3 5 8 13 7 Output Input
The  while S tatement Syntax: while ( condition ) statement(s);
The  do…while S tatement Syntax: do statement(s); while ( condition );
Nested Loops The term  nested loops  refers to a loop that is contained within another loop.
Exercises Create an algorithm that continually inputs one integer (N) and then displays a triangle (N rows). The algorithm will be terminated when the input is zero. E.g.: 4 Output Input
Exercises A mathematics' formula is shown by: Sn = (2 * n) + 3 Un = Sn + Sn- 1  + … + S 0 Create an algorithm that continually inputs one integer (n) and then displays the result (Un) on screen. The algorithm will be terminated when the input is minus one.

Loop Statements [5] M

  • 1.
    Programming & AlgorithmLoop Statements August 07, 2006
  • 2.
    Array: The BasicAn Array is an indexed group of data storage that have the same name and are distinguished from each other by an index (that is a number following the variable name, enclosed in brackets). A single-dimensional array declaration has the following form: typename array_name[size]; Note : The first index of an array is zero .
  • 3.
    Loop Statement Thefunction is to execute one/some statement(s) several times. There are three loop statements: for statement while…do statement do…while statement
  • 4.
    The forS tatement Syntax: for ( initial ; condition ; increment ) statement(s);
  • 5.
    The forS tatement E.g.: Display the words “Welcome to this cruel world..” ten times. for (i ← 0; i ≤ 9; i ← i + 1) output(“Welcome to this cruel world..”)
  • 6.
    Exercises Create analgorithm that displays numbers (1 to 25) on screen. Create an algorithm that uses loop statements to displays following formation of ‘*’ character on screen. a. b. c.
  • 7.
    Exercises Create analgorithm that prints the result of X powered by Y. The algorithm received two numbers of integer (X and Y). Create an algorithm that asks one number of integer (N) and displays the numbers of Fibonacci on screen. E.g.: 1 1 2 3 5 8 13 7 Output Input
  • 8.
    The whileS tatement Syntax: while ( condition ) statement(s);
  • 9.
    The do…whileS tatement Syntax: do statement(s); while ( condition );
  • 10.
    Nested Loops Theterm nested loops refers to a loop that is contained within another loop.
  • 11.
    Exercises Create analgorithm that continually inputs one integer (N) and then displays a triangle (N rows). The algorithm will be terminated when the input is zero. E.g.: 4 Output Input
  • 12.
    Exercises A mathematics'formula is shown by: Sn = (2 * n) + 3 Un = Sn + Sn- 1 + … + S 0 Create an algorithm that continually inputs one integer (n) and then displays the result (Un) on screen. The algorithm will be terminated when the input is minus one.