REW

How To Input An Array In Raptor?

Published Aug 29, 2025 5 min read
On this page

Inputting an array in RAPTOR involves using a loop to repeatedly prompt the user for input and storing each value in a specific indexed position of the array.

Unlike many programming languages, RAPTOR does not require a formal declaration of an array's size beforehand; the array grows dynamically as elements are added. You simply begin using the array with an index, and RAPTOR creates and expands it as needed.

Step-by-step process for inputting an array

The most common method for populating an array with user input is to use a loop structure, such as a While loop or a For loop, which processes a specific number of inputs.

Method 1: Using a For loop (Count-controlled)

This method is most straightforward when the number of elements is known in advance.

  1. Start a new RAPTOR flowchart.
  2. Add a variable for the array size. Use an Input symbol to ask the user how many elements they want to enter. Store the result in a variable, such as array_size.
  3. Create an index variable. Use an Assignment symbol to set a counter variable, such as i, to 1. RAPTOR arrays are 1-indexed, meaning the first element is at position 1.
  4. Insert a loop. Drag a Loop symbol and set the condition to i <= array_size.
  5. Add an input inside the loop. Inside the loop, add an Input symbol.
    • Prompt: For a clear user experience, use a descriptive prompt like "Enter value for position " + i + ":".
    • Get: Set the input variable to the array element using the index, for example, my_array[i]. This creates the array and its elements as the loop runs.
  6. Increment the counter. Add an Assignment symbol to increment the index variable: i <- i + 1.
  7. Run the flowchart. The program will prompt the user for input for each position in the array.

Example walkthrough:

  • Symbol:Input
    • Prompt:"Enter the number of elements:"
    • Get:array_size
  • Symbol:Assignment
    • Set:i
    • To:1
  • Symbol:Loop
    • Condition:i <= array_size
  • Inside the loop:
    • Symbol:Input
      • Prompt:"Enter number for position " + i
      • Get:my_array[i]
    • Symbol:Assignment
      • Set:i
      • To:i + 1

Method 2: Using a While loop (Sentinel-controlled)

This method is useful when the number of elements is unknown beforehand, allowing the user to stop entering values by providing a specific "sentinel" value (e.g., a negative number or zero).

  1. Start a new RAPTOR flowchart.
  2. Initialize variables. Use an Assignment symbol to set up the loop index and a variable to hold the input. For example, i <- 1 and input_value <- 0.
  3. Add an initial Input symbol. Prompt the user for the first value, telling them what the sentinel value is.
    • Prompt:"Enter a positive number (or 0 to stop):"
    • Get:input_value
  4. Insert a loop. Add a Loop symbol and set the condition to continue as long as the input is not the sentinel value: input_value != 0.
  5. Store the input. Inside the loop, add an Assignment symbol to place the input_value into the array at the current index: my_array[i] <- input_value.
  6. Increment the counter. Add an Assignment symbol to increase the index for the next element: i <- i + 1.
  7. Add another Input symbol. At the end of the loop, prompt the user for the next value. This is a crucial step for the loop to continue:
    • Prompt:"Enter next number (or 0 to stop):"
    • Get:input_value
  8. Run the flowchart. The loop will continue until the user enters the designated sentinel value.

Example walkthrough:

  • Symbol:Assignment
    • Set:i
    • To:1
  • Symbol:Input
    • Prompt:"Enter a number (0 to stop):"
    • Get:input_value
  • Symbol:Loop
    • Condition:input_value != 0
  • Inside the loop:
    • Symbol:Assignment
      • Set:my_array[i]
      • To:input_value
    • Symbol:Assignment
      • Set:i
      • To:i + 1
    • Symbol:Input
      • Prompt:"Enter next number (0 to stop):"
      • Get:input_value

Key concepts and best practices

Array creation and dynamic sizing

In RAPTOR, a separate declaration step to create an array is not needed. An array is automatically created and resized the moment a value is assigned to an indexed variable, like my_array[1]. This simplifies array handling but can lead to errors if attempting to access an element beyond the current highest index.

Array indexing

RAPTOR's array indices begin at 1, not 0. This is a key difference from many other languages and is important to remember when setting up loops and accessing elements.

Using Length_Of

After the user has finished inputting values, the final size of the array can be determined using the Length_Of function, for example, Length_Of(my_array). This is useful for subsequent processing, such as displaying the array's contents or finding the average.

Error handling

Consider how the program will handle unexpected user input.

  • Non-numeric input: If the program expects numbers but the user enters text, RAPTOR will produce a runtime error. Nested loops and validation checks can prevent this, but for simple flowcharts, it's often assumed the user will provide valid input.
  • Sentinel value issues: Ensure the sentinel value is a number the user is unlikely to enter as a valid data point. For example, using 0 for an array of positive numbers is a good choice.

Displaying the array

After inputting the data, another For loop can iterate through the array and display its contents to the user, confirming that the input process was successful.

Example:

  • Symbol:Assignment
    • Set:j
    • To:1
  • Symbol:Loop
    • Condition:j <= Length_Of(my_array)
  • Inside the loop:
    • Symbol:Output
      • Output:"Element at position " + j + ": " + my_array[j]
    • Symbol:Assignment
      • Set:j
      • To:j + 1

Summary of RAPTOR array input logic

The logical process for creating and populating an array with user input in RAPTOR is as follows:

  1. Prepare: Initialize a counter variable, typically named i, to 1.
  2. Loop: Create a loop, either a While loop for an unknown number of items (using a sentinel value) or a For loop for a fixed number of items.
  3. Prompt: Inside the loop, use an Input symbol to prompt the user for a value.
  4. Assign: Store the user's input directly into the array using the counter variable as the index (e.g., my_array[i]). RAPTOR automatically creates or resizes the array during this assignment.
  5. Increment: After the assignment, increment the counter variable to move to the next position in the array.
  6. Repeat: The loop continues until the exit condition is met, at which point the array is fully populated with user-provided data.
Enjoyed this article? Share it with a friend.