Skip to main content

Lists and Iteration

The Nada DSL supports the use of iteration over lists that contain secret integer values. This includes limited use of for loops.

Basic Example

The program below uses a Python for loop to build an ascending sequence of three secret integers in which the first entry is a secret integer input. This sequence of secret integers is then returned by the program. Notice that when the lists sequence and outputs are first defined, their types are explicitly specified using a Python type annotation.

Voting Example using Iteration over Lists

The program below assembles the secret votes from four voting parties (i.e., voters) and returns the total for each of the two candidates. Because each voting party submits an input of either 1 or 2 for candidate, the value Integer(4) is subtracted from the total for each candidate.

A for loop is used to build up the list of parties corresponding to the voters using the append method for lists. A for loop nested inside another for loop is used to assemble a list of lists votes_per_candidate that contains two lists (i.e., a list of the votes submitted for the first candidate and a list of the votes submitted for the second candidates). Finally, the list of outputs is assembled using a for loop and returned.