0

I am using the Xtend templates to write a small program. I try using the IF statement, but every time I execute it it prints the variable in the console, which I dont want it to.

  «IF x==y»
    The jump value is «database.get(2)»
    «jump_var_letter = String.charAt(1)»
    «old_jump_ahd=database.get(2) »
  «ENDIF»   

Here the database is an array of integers and String is an array of letters. Here I just want it to print the value found at database.get(2) i.e 5. The last two expressions befor the ENDIF is meant for assignning a few values( which need not be printed)

 The jump value is 5

Instead I get

 The jump value is 5
  D
  5

Could somebody please tell me how I could stop printing the other two values. Thank you in advance for your help..

Goldengirl
  • 957
  • 4
  • 10
  • 30

1 Answers1

1

After looking for sometime on the net I found that you could prevent the printing of the expreesions in between by using block expressions and then returning a null expression. (Although this method is not encouraged, I found that it provides me the result I wanted). So the expression I posted could be written as:

«IF x==y»
      The jump value is «database.get(2)»
      «{jump_var_letter = String.charAt(1); "" }»
      «{old_jump_ahd=database.get(2); ""} »
«ENDIF» 

This prints

  The jump value is 5.
Goldengirl
  • 957
  • 4
  • 10
  • 30
  • 2
    You might want to think about structuring your code into template and non-template code. There is no need to put every last bit of code into those. Think about calling helper methods once in a while that are non-template expressions with return statements instead. – Franz Becker Jul 27 '15 at 21:09