Chapter 8. YCP Program Structure

Table of Contents

8.1. Comments
8.2. Variable Declaration
8.3. Variable Assignment
8.4. Conditional Branch
8.5. while() Loop
8.6. do..while() Loop
8.7. repeat..until() Loop
8.8. break Statement
8.9. continue Statement
8.10. return Statement
8.11. Function definition
8.12. Function declaration
8.13. include Statement
8.14. import Statement
8.15. Variable Scopes and blocks
8.16. Applying Expressions To Lists And Maps

Now that we have learned how data can be stored and evaluated in YCP, we will take a look at the surrounding code structure that can be realized. Code structure is created by means of blocks and statements.

8.1. Comments

Despite not being really statements, comments do (and should) belong to the overall structure of a YCP program. There are two kinds of comments:

  • Single-line comments

    Single-line comments may start at any position on the line and reach up to the end of this line. They are introduced with //.

  • Multi-line comments

    Multi-line comments may also start at any position on the line but they may end on another line below the starting line. Consequently there must be a start tag (/*) and an end tag (*/) as is shown below.

Example 8.1. Comments

{
    // A single-line comment ends at the end of the line.

    /*
      Multi-line comments
      may span several lines.
    */

    y2milestone("This program runs without error");
}