Skip to content

Commit

Permalink
Reworked example to show two kinds of 'foreach' use
Browse files Browse the repository at this point in the history
  • Loading branch information
skx committed Feb 1, 2020
1 parent e73950c commit fa0b291
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions _examples/scripts/sorting.script
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ input = [ "Hello", "my", "name", "is", "Steve" ];
// Show the array contents.
//
print("Showing array items:\n");
foreach entry in input {
print("\t", entry, "\n" );
foreach index,entry in input {
printf("\t%d:%s\n", index, entry );
}


Expand All @@ -32,8 +32,8 @@ foreach entry in input {
//
print( "Showing sorted array items:\n");
sorted = sort(input);
foreach entry in sorted {
print("\t", entry, "\n" );
foreach index,entry in sorted {
printf("\t%d:%s\n", index, entry );
}

//
Expand All @@ -46,11 +46,12 @@ foreach entry in reversed {
}

//
// Just to recap
// Just to recap what we had
//
print( "Original:", input, "\n");
print( "Sorted:", sorted, "\n");
print( "Reversed:", reversed, "\n");
print( "\n" );
print( "Original input:", input, "\n");
print( "Sorted result:", sorted, "\n");
print( "Reversed list:", reversed, "\n");


//
Expand Down

0 comments on commit fa0b291

Please sign in to comment.