The basic syntax that you need to use is:
FOR i = 1 to NoOfRows('tab1')
LET a = fieldvalue('ID', $(i)) ;
// ENTER YOUR CODE HERE
In both of your examples you dont have the NEXT statement. Also remember that you need to use the dollar expansion around your variable.
Hope this helps.