Syntax
Opens a block where \field stands for <record>.field, anywhere on the line, to write less when many lines touch one record.
WITH <record>
\<field> …
\<field>\<subfield> …
\<field>.<subfield> …
ENDWITH
END WITHAlso written : ENDWITH
Parts
| <record> | Any record expression: a variable, fleet(i), the current list element foes(). |
|---|---|
| <field> | A field of the record. |
| <subfield> | A field of a record field. Write the chain with \ or with .. |
Good to know
- The block closes with
ENDWITHorEND WITH. - The record expression is re-read at every
\. WithWITH fleet(i), changingiinside the block moves the following lines to another cell. - WITH blocks do not nest. A WITH inside a WITH is a compile error: "Nested WITH blocks are not supported".
- Text in strings and comments is left alone:
"C:\games"stays a path. - Outside a WITH,
hero\fuelis refused with "Not a BASIC statement". Writehero.fuel. - One word after
WITHmakes a record block. Two words, the first a command family (WITH SPRITE s), make the command shorthand instead.
Example
TYPE Vec x AS float y AS floatENDTYPETYPE Ship name AS string fuel AS integer pos AS VecENDTYPEs AS ShipWITH s \name = "Comet" \fuel = 80 \pos\x = 1.5 \pos.y = 2.5 Console(\name + " " + Str(\fuel) + " " + Str(\pos\x + \pos\y)) ' Comet 80 4ENDWITHIn the manual : Records and methods