Writing Blocks of Code

Navigation:  Macros > Writing Macros >

Writing Blocks of Code

Previous pageReturn to chapter overviewNext page

In the Q++ macro language, there are many structures which involve blocks of code framed by delimiting keywords at the beginning and end of the block. One example is the if-else-endif branching structure (other examples are the while, for and switch structures).



 // do something


 // do something else



There are 2 potential sources of errors stemming from blocks of code :


Misalignment of the keywords that mark the start and finish of a block can lead to logical bugs in your code (ie. the macro does compile but does not produce the expected results).


Missing keywords at the end of the macro will generate a compilation error.


To prevent both types of errors, we suggest that you always write the entire skeleton of a block before writing the code inside. For example, in the case of an if-else-endif block you would follow the sequence:




In the above sequence, all you need to do is type "if" then press RETURN twice then write "else" then press RETURN twice then write "endif". The automated indentation of the Macros Editor ensures that each of the keywords is indented properly so that your code reads as it is processed.

Topic 172160 updated on 01-Nov-2016.
Topic URL: http://www.qppstudio.net/webhelp/index.html?writingblocksofcode.htm