MasteringVFP/2/4/1
出自VFP Wiki
在2009年5月21日 (四) 13:32由VarpaSrict (對話 | 貢獻)所做的修訂版本
http://www.textacelca.com For-loop,æè®å¤¾å¨ For è next ä¹éçç¨å¼éè¤å·è¡ n 次. èä¾ä¾èªª:
For i=1 to 10 ? "Hello world" next
å°±æå°åºå次 "Hello world"
å¦å¤ä¸åè®åå½¢çæç¨,æ¯å¦é樣:
For i=1 to 10 step 2 ? "Hello world" next
é樣就åªæå°åºäºæ¬¡ "Hello world" å.
å¦ææ³å¨ For-loop 裡é¢ä½å¤æ·,符åæ¢ä»¶å°±è·³åº,é£éº¼ä½ å¯ä»¥é©æçå ä¸ if, continue è exit. å¦ä¸ä¾:
For i=1 to 10 if i=5 exit else ? "Hello world" continue endif next <pre> ç¶ i=5 çæå,å°±æè·³åºè¿´å,å¦æå°æ¼ 5 ç話,åå°åº "Hello world",並繼çºéåè¿´å. ---- = FOR ... ENDFOR å½ä»¤ = == ç¨é == :ææå®ç次æ¸éè¤å·è¡ä¸çµå½ä»¤ã == èªæ³ == :FOR ''Var'' = ''nInitialValue'' TO ''nFinalValue'' [STEP ''nIncrement''] ::''Commands'' ::[EXIT] ::[LOOP] :ENDFOR | NEXT == åæ¸ == === ''Var'' === *æå®ä½çºè¨æ¸å¨çè¨æ¶é«è®æ¸æé£åå ç´ ãå¨ FOR ... ENDFOR å·è¡ä¹åï¼æ¤è¨æ¶é«è®æ¸æé£åå ç´ ä¸ä¸å®åå¨ã === ''nInitialValue'' TO ''nFinalValue'' === *''nInitialValue'' æ¯è¨æ¸å¨çåå§å¼ï¼è ''nFinalValue'' æ¯è¨æ¸å¨ççµæ¢å¼ã === STEP ''nIncrement'' === *''nIncrement'' æ¯è¨æ¸å¨éå¢æéæ¸çæ¸éãå¦æ ''nIncrement'' çºè² ï¼åè¨æ¸å¨éæ¸ï¼å¦æçç¥ STEP åå¥ï¼è¨æ¸å¨æ¯æ¬¡çå¢éçº 1ã === ''Commands'' === *æå®è¦å·è¡ç Visual !FoxPro å½ä»¤ï¼''Commands'' å¯ä»¥å å«ä»»ææ¸ç®çå½ä»¤ã === EXIT === *å¨ FOR ... ENDFOR 循ç°ä¸ï¼å°æ§å¶æ¬è¿ é移è½çµ¦ç·æ¥å¨ ENDFOR çä¸ä¸åå½ä»¤ãæ¨å¯ä»¥å° EXIT å¯ä»¥æ¾å¨ FOR è ENDFOR ä¹éçä»»ä½ä½ç½®ã === LOOP === *å°æ§å¶æ¬ç´æ¥å³çµ¦ FOR åå¥ï¼ä¸åå·è¡ LOOP è ENDFOR ä¹éçæè¿°ãè¨æ¸å¨æ£å¸¸éå¢æéæ¸ï¼å°±åå·è¡å° ENDFOR ä¸æ¨£ãLOOP å¯ä»¥æ¾å¨ FOR è ENDFOR ä¹éçä»»ä½ä½ç½®ã == é註 == *å¯ä»¥ç¨è¨æ¶é«è®æ¸æé£åå ç´ ä½çºè¨æ¸å¨ï¼æå® FOR ... ENDFOR 循ç°ä¸ Visual !FoxPro å½ä»¤çå·è¡æ¬¡æ¸ã *å¨éå° ENDFOR æ NEXT ä¹åï¼å§çµå·è¡ FOR å¾é¢ç Visual !FoxPro å½ä»¤ãå·è¡éç¨ä¸ï¼æ¯å¾ªç°ä¸æ¬¡ï¼è¨æ¸å¨ ''Var'' é½æéå¢ï¼å¢éçº ''nIncrement''ï¼å¦æçç¥ STEP åå¥ï¼åè¨æ¸å¨æ¯æ¬¡çå¢éçº 1ï¼ï¼ç¶å¾æè¨æ¸å¨çå¼è ''nFinalValue'' ä½æ¯è¼ãå¦æè¨æ¸å¨çå¼å°æ¼æçæ¼ ''nFinalValue''ï¼å°å次å·è¡ FOR åå¥å¾çå½ä»¤ï¼å¦æè¨æ¸å¨çå¼å¤§æ¼ ''nFinalValue''ï¼åéåº FOR ... ENDFOR 循ç°ï¼ç¨åºç¹¼çºå·è¡ ENDFOR æ NEXT ä¹å¾çä¸ä¸åå½ä»¤ã **'''注æ''' ::''nInitialValue''ã''nFinalValue'' å ''nIncrement'' åªè½æ¯å次è®å ¥çå¼ãå¨å¾ªç°éç¨ä¸æ´æ¹è¨æ¸å¨ ''Var'' çå¼å°å½±é¿å¾ªç°çå·è¡æ¬¡æ¸ã *å¦æ ''nIncrement'' çºè² ï¼ä¸åå§å¼ ''nInitialValue'' 大æ¼çµæ¢å¼ ''nFinalValue''ï¼åæ¯ç¶éä¸æ¬¡å¾ªç°ï¼è¨æ¸å¨é½å°éæ¸ã == ç¯ä¾ == å¨ç¯ä¾ 1 ä¸ï¼é¡¯ç¤ºæ¸å 1 å° 10ã ç¯ä¾ 2 使ç¨è¨æ¶é«è®æ¸ä½çºåå§å¼ãçµæ¢å¼å STEP å¼ï¼é¡¯ç¤º customer è³æè¡¨æ ¼ä¸å¾ 2 èå° 10 èè¨éä¸ææè¨éèçºå¶æ¸çè¨éã ç¯ä¾ 1 <pre> CLEAR FOR gnCount = 1 TO 10 ã? gnCount ENDFOR ç¯ä¾ 2 SET TALK OFF CLOSE DATABASES OPEN DATABASE (HOME(2) + 'Data\testdata') USE customerããã && éå Customer è³æè¡¨æ ¼ STORE 2 TO gnIãã && åå§å¼ STORE 10 TO gnJãã&& çµæ¢å¼ STORE 2 TO Kããã && Step å¼ FOR gnCount = gnI TO gnJ STEP K ãGOTO gnCountãã && 移åè¨éææ¨ ãDISPLAY companyã&& é¡¯ç¤ºå ¬å¸å稱 ENDFOR