# ObjectScript Quick Introduction

Here's the world's quickest introduction to ObjectScript commands, operators, and functions.

Commands
 Set Assign a value to a variable, e.g. SET A = 1 Do Execute a method or subroutine, e.g. DO X(43) If ... ElseIf ... Else Conditional execution (THEN is implicit). For Loop using a counter, e.g. FOR X = 1 : 1 : 100 In FOR X = A : B : C, A is the starting value, B the increment, and C the ending value. While & Do ... While Loop until a condition is true, e.g.WHILE A < 10 { SET B = B + 1 }. Quit Exit from a method, subroutine or FOR loop
Operators
 + - * / The usual arithmetic operators: addition, subtraction, multiplication, division. ** Exponentiation. \ Integer Division. # Modulo. = < > Logical Comparisons. ' Logical NOT (a single quote). && || Logical AND and OR. _ String concatenation (an underscore). ? Pattern match. Very powerful, but too rich to explain here.
Functions
 \$Case Compare an expression with a set of cases and return the value associated with the first matching case. For instance, \$CASE(X, 6:"Weekend",7:"Weekend",:"Weekday"), returns “Weekend” if X equals 6 or 7 and “Weekday” otherwise. \$Extract Return a portion of a string. \$Find Find characters within a string. \$FNumber Format a number, e.g. \$FNUMBER(X, ",", 2) uses commas as the thousands separators and displays two decimal places. \$Get Fetch the value of a variable or return a default value if the variable is undefined, e.g. SET A = \$GET(X, 3) —If X is undefined, A = 3, otherwise A = X. \$Horolog Get the current date and time. \$Length Determine the length of a string. \$List One of a set of functions for manipulating lists. \$Piece Extact substrings from a string using a delimiter character. \$Translate Perform character translations. \$Zdate Formats a date value. \$Ztime Formats a time value.
{"ft_lang_label":"__label__en","ft_lang_prob":0.6521792,"math_prob":0.9709448,"size":1950,"snap":"2023-14-2023-23","text_gpt3_token_len":534,"char_repetition_ratio":0.09249743,"word_repetition_ratio":0.0,"special_character_ratio":0.2851282,"punctuation_ratio":0.21827412,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97190124,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-06-02T12:00:41Z\",\"WARC-Record-ID\":\"<urn:uuid:38ab7591-7072-4b7a-bcc5-d68dd0756c3f>\",\"Content-Length\":\"16299\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:06e206f9-a10d-4cc6-94a3-d42b3256072a>\",\"WARC-Concurrent-To\":\"<urn:uuid:59643fae-7daf-4ed0-98a1-4daa55f9216b>\",\"WARC-IP-Address\":\"198.133.74.116\",\"WARC-Target-URI\":\"https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=TWEB2_ObjectScriptIntro\",\"WARC-Payload-Digest\":\"sha1:PLL5G4LA3F7GVOV3A2JA2OS4CS7ZKKNM\",\"WARC-Block-Digest\":\"sha1:2P6G5XDPITG62BEPOERUQRKH5WFPDNYJ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224648635.78_warc_CC-MAIN-20230602104352-20230602134352-00124.warc.gz\"}"}