Skip to content

Commit

Permalink
Make Array.qs in /samples/language more user-friendly (#1504)
Browse files Browse the repository at this point in the history
#1470

---------

Co-authored-by: Joshua Aragon <jaragon32@microsoft.com>
Co-authored-by: Manvi-Agrawal <40084144+Manvi-Agrawal@users.noreply.github.com>
  • Loading branch information
3 people committed May 10, 2024
1 parent 1564178 commit 5d092b6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion samples/language/Array.qs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,25 @@ namespace MyQuantumApp {

// A basic Int Array literal
let intArray : Int[] = [1, 2, 3, 4];
Message($"Integer Array : {intArray} of length {Length(intArray)}");

// A basic String Array literal
let stringArray = ["a", "string", "array"];
Message($"{stringArray}");

// A new array expression creating the array `[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]`
let repeatedArray = Repeated(0, 10);
let repeatedArray = [0, size = 10];
Message($"{repeatedArray}");
let repeatedArray = Repeated(0, 10); // contains [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Message($"{repeatedArray}");

// Arrays can be sliced with ranges.
let slice = intArray[1..2..4]; // contains [2,4]
Message($"{slice}");
let slice = intArray[2..-1..0]; // contains [3,2,1]
Message($"{slice}");
let slice = intArray[...]; // contains [1, 2, 3, 4];
Message($"{slice}");

return intArray;
}
Expand Down

0 comments on commit 5d092b6

Please sign in to comment.