Seed7 Example: Echo the program arguments

Seed7 FAQ Manual Demo Screenshots Examples Libraries Algorithms Benchmarks Index Download GitHub Build Seed7 Links
Examples echo args file in string simple clock count words subtype map function generic func declare stmt template operator 3-way if
Examples Echo the program arguments

This example program writes its arguments

$ include "seed7_05.s7i"; # Standard Seed7 library
const proc: main is func
 local
 var string: stri is "";
 begin
 for stri range argv(PROGRAM) do
 write(stri <& " ");
 end for;
 writeln;
 end func;

Everything between # and the end of the line is a comment which is ignored.

The keyword 'local' introduces local declarations. In this case the string variable 'stri' is declared and initialized with "", the empty string literal.

The function argv(PROGRAM) returns the program arguments as array of strings. The 'for' (for-each) loop iterates over all elements of this array . The for-each statement is overloaded for various collection types.

The <& operator is used to concatenate elements before writing. If one operand of the <& operator has not the type string it is converted to a string using the 'str' function.

AltStyle によって変換されたページ (->オリジナル) /