Using code templates

In this section you will use content assist to fill in a template for a common loop structure. Open Test.js file in the VJET editor if you do not already have it open.

  1. Start adding a new method by typing the following:
    //> public void printAccount()
    printAccount : function () {
        if
    }
    
  2. With the cursor at the end of if, press Ctrl+Space to enable content assist.  You will see a list of common templates for "if "statement.  When you single-click a template, you'll see the code for the template in its help message.  Note that the local array name is guessed automatically.

    Content assist for If

  3. Choose the ifesle-if-else statement entry and press Enter to confirm the template.  The template will be inserted in your source code.

    Inserted if-else template

  4. Next we change the name of the variable from condition to this.isOpenAccount(). To do so simply press condition, as the index variable is automatically selected.

    Note: the name of the selected variable changes at all places. When a template was inserted, all references to the same variable are connected to each other. So changing one changes all the other values as well.

    Altered for template

  5. Complete the for loop as follows:
    //> public void printAccount()
    printAccount: function() {
        if (this.isOpenAccount()) {
            vjo.sysout.println("Your account number is: 123456.");
        } else {
            vjo.sysout.println("You do not have an account.");
        }
    }
    
  6. Save the file.

Related reference