ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ¨D±Ï ¦³Ãönested loop

[µo°Ý] ¨D±Ï ¦³Ãönested loop

·Q¼g¤@­Ó­p¼ÆªºVBA
±¡ªp¬O³o¼Ëªº

¨DÀ°¦£¬Ý¬Ý
²Ä¤@­Óloop ¼g¤F¬O³o¼Ë
¤@¶}cells(1,1) ¤Î cells(2,1)¬O¤£ª¾¦h¤Öªº
§Ú¥ý°²³]¬O¬Y¤@¼Æ­È (¤U­±ªººâ¦¡¬OÀH«K¼gªº ¬O¤£¥¿½Tªº)


Cells(3,1)=cells(1,1)*4-1
Cells(4,1)=cells(2,1)/6
do until Abs(Cells(4,1)-Cells(3,1)) <=0.0005
if Cells(4,1)-Cells(3,1) >0.0005 then cells(2,1)=cells(2,1)+0.0001
cells(3,1)=Cells(1,1)*4-1
Cells(4,1)=Cells(2,1)/6
loop
Cells(5,1)=cells(3,1)-2
Cells(6,1)=cells(4,1)/3
¤§«á·Q¼g ¦pªGdo until Abs(Cells(7,1)-Cells(6,1)) <=0.0005 ¦pªG¤£¬Oªº¸Ü cells(1,1) ·|¦A¥[0.00001
³o®Écells(2,1)¤w¤£¤@¶}©l¦Û¤vassume ªº¼Æ­È ¥¦·|¦A¥Ñ0¶}©l¸Õ ¸Õ¨ìAbs(Cells(4,1)-Cells(3,1)) <=0.0005

À³¸Ó¦pªG¼g
(©êºp »¡±o¤£¬O«Ü¥Õ©ú
Á`¤§±¡ªp¬O¦p¤W¹Ï©Ò¥Ü)
²©ö¤@ÂIªº¸ÜÀ³¸Ó¬O  ¤º­±ªºloop¦pªGº¡¨¬±ø¥óªº¸Ü ·|¥h¥~­±ªºloop
ª½¨ì2­Óloop¦P®Éº¡¨¬±ø¥ó

ÁÂÁÂ

¦^´_ 1# drgv11

Sub test()
Do
[a1] = InputBox(1)   'assume [a1]
[a2] = InputBox(1)   'assume [a2]
    Do
        Cells(2, 1) = Cells(2, 1) + 0.0001      'ReAssume [a2]
        Cells(3, 1) = Cells(1, 1) * 4 - 1       'calculate [a3]
        Cells(4, 1) = Cells(2, 1) / 6           'calculate [a4]
        [a5] = Abs(Cells(4, 1) - Cells(3, 1))   '¥iÆ[¹î ­pºâ¹Lµ{
        '¦pªG[a5]·U¨Ó·U¤j,«h¤£¥i¯à¸õ¥X°j°é, ½Ð«ö ESC, ­«³][a1],[a2]ªº­È,
        '©Î [a3],[a4]­pºâ¤½¦¡
    Loop Until [a5] <= 0.0005
    '­Yª½±µ¼g¦¨ Loop Until Abs(Cells(4, 1) - Cells(3, 1)) <= 0.0005
    '«hµLªkÆ[¹î ­pºâ¹Lµ{
Cells(5, 1) = Cells(3, 1) - 2
Cells(6, 1) = Cells(4, 1) / 3
'
[a7] = Abs(Cells(5, 1) - Cells(6, 1)) <= 0.0005 '¥iÆ[¹î ­pºâµ²ªG
'¦¹³B Abs(Cells(7, 1) - Cells(6, 1)) <= 0.0005 À³¬O¼Ó¥DCells(5, 1)µ§»~?
Loop Until [a7] <= 0.0005
End Sub

TOP

ª½±µ¨D¸Ñ´N¥i¥H¤F
«D­n¥Î¦^°é¶Ü ?

TOP

¦^´_ 1# drgv11
¤â°Ê¿é¤J Cells(1,1)
¤â°Ê¿é¤J Cells(2,1)
Cells(3,1)=cells(1,1)*4-1
Cells(4,1)=cells(2,1)/6
do until Abs(Cells(4,1)-Cells(3,1)) <=0.0005
  if Cells(4,1)-Cells(3,1) >0.0005 then cells(2,1)=cells(2,1)+0.0001
  Cells(3,1)=Cells(1,1)*4-1
  Cells(4,1)=Cells(2,1)/6
loop

­Y Cells(2,1) ¬°¥¿¼Æ,
¥B Cells(4,1)-Cells(3,1) >0.0005 «h
²Ä1­Ó°j°é±N¦¨¬°µL­­°j°é.

ÃÒ©ú :
³] Cells(1,1)=A , Cells(2,1)=B ¥B  Cells(4,1)-Cells(3,1) >0.0005
«h
Cells(3,1)=A*4-1
Cells(4,1)=B/6
Cells(4,1)-Cells(3,1)
=B/6-(A*4-1)
=B/6-4A+1 > 0.0005
¨Ìµ{¦¡¤U¤@½ü cells(2,1)=B+0.0001
Cells(4,1)-Cells(3,1)
=(B+0.0001)/6+4A+1 > B/6-4A+1 => ¥u·|¶V¨Ó¶V¤j
©Ò¥H Cells(4,1)-Cells(3,1) <= 0.0005 ¥Ã»·¤£·|¦¨¥ß.
±oÃÒ.

µù : §Ú¤£¬O¼Æ¾Ç®a, ÃÒ©ú¨BÆJ«D¥¿³W, ½Ð¨£½Ì.

TOP

        ÀR«ä¦Û¦b : ºÉ¦h¤Ö¥»¥÷¡A´N±o¦h¤Ö¥»¨Æ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD