ÒÔÏÂʾÀýÑÝʾÁËÈçºÎʹÓà for each Óï¾äö¾Ùvisual foxpro Êý×éÖеÄÔªËØ¡¢Ò»¸öole Êý×éºÍ¸³¸ø¶ÔÏóÊý×éµÄÒ»Ì×ÃüÁî°´Å¥¡£
ÒÔÏÂʾÀýÖд´½¨ÁËÒ»¸ö visual foxpro ±äÁ¿²¢Ê¹Óà for each Óï¾äÏÔʾÊý×éÖÐÿ¸öÔªËØµÄÄÚÈÝ¡£
dimension cmyarray(3)
cmyarray[1] = 'a'
cmyarray[2] = 'b'
cmyarray[3] = 'c'
for each cmyvar in cmyarray
? cmyvar
endfor
ÔÚÒÔÏÂʾÀýÖУ¬´´½¨ÁËÒ»¸ö microsoft excel ʵÀý£¬Ìí¼ÓÁËÒ»¸öÐµĹ¤×÷²¾¡£Ê¹Óà foreach Óï¾äÏÔʾ¹¤×÷²¾ÖÐÿ¸ö¹¤×÷±íµÄÃû³Æ¡£´ËʾÀýÒªÇóÔÚÔËÐÐʾÀýµÄ»úÆ÷ÉÏÕýÈ·°²×° microsoft excel¡£
oexcel = create("excel.application")
oexcel.workbooks.add
for each omyvar in oexcel.sheets
? omyvar.name
next omyvar
ÔÚÒÔÏÂʾÀý£¬ÔÚ±íµ¥·ÅÖÃÁËÎå¸öÃüÁî°´Å¥¡£Ê¹Óà for each ÃüÁîÏÔʾ±íµ¥Éϵİ´Å¥²¢Ö¸¶¨ËüÃǵıêÌâ¡¢×ÖÌåºÍÿ¸ö°´Å¥µÄλÖá£
public omyobject
omyobject = createobject("frmtest")
omyobject.show
define class frmtest as form
height = 200
dimension myarray[5]
procedure init
for i = 1 to 5
this.addobject('this.myarray[i]',;
'commandbutton')
endfor
****** for each - next ******
for each obutton in this.myarray
obutton.visible = .t.
next
****** for each - next element ******
for each obutton in this.myarray
obutton.fontbold = .t.
next obutton
j = 1
****** for each - endfor ******
for each obutton in this.myarray
obutton.top = j * 30
j = j + 1
endfor
****** for each - endfor element ******
for each obutton in this.myarray
obutton.fontitalic = .t.
endfor obutton
j = 1
****** exit ******
for each obutton in this.myarray
obutton.caption = "test" + str(j)
j = j+1
if j > 3
exit
endif
next
j = 1
****** loop ******
for each obutton in this.myarray
if j > 3
loop
endif
j = j + 1
obutton.left = 25
next
endproc
enddefine