{"id":955,"date":"2015-03-25T13:10:05","date_gmt":"2015-03-25T04:10:05","guid":{"rendered":"http:\/\/excelwork.info\/excel\/?p=955"},"modified":"2015-03-25T19:36:40","modified_gmt":"2015-03-25T10:36:40","slug":"iteration_doloop","status":"publish","type":"post","link":"https:\/\/excelwork.info\/excel\/iteration_doloop\/","title":{"rendered":"\u7e70\u308a\u8fd4\u3057\u51e6\u7406\uff08Do&#8230;Loop \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\uff09"},"content":{"rendered":"<h2>Do&#8230;Loop \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u306e\u4f7f\u3044\u65b9<\/h2>\n<div class=\"m30-l\">\n<br \/><\/p>\n<div class=\"kkbox\"><strong>\u3010\u69cb\u6587 1\u3011<\/strong><\/p>\n<p><strong>Do<\/strong> [ <strong>While<\/strong> (\u307e\u305f\u306f <strong>Until<\/strong>) <em>condition<\/em> ]<\/p>\n<p>\u3000\u3000[ <em>statements<\/em> ]<\/p>\n<p>Loop<\/p>\n<\/div>\n<br \/>\n<div class=\"kkbox\"><strong>\u3010\u69cb\u6587 2\u3011<\/strong><\/p>\n<p><strong>Do<\/strong><\/p>\n<p>\u3000\u3000[ <em>statements<\/em> ]<\/p>\n<p><strong>Loop<\/strong> [ <strong>While<\/strong> (\u307e\u305f\u306f <strong>Until<\/strong>) <em>condition<\/em> ]<\/p>\n<\/div>\n<h3>\u3010\u9805\u76ee\u306e\u8aac\u660e\u3011<\/h3>\n<ul style=\"margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0;\">\n<li>condition&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u771f (True) \u307e\u305f\u306f\u507d (False) \u3092\u8a55\u4fa1\u3059\u308b\u6570\u5f0f\u3001\u6587\u5b57\u5217\u5f0f\u3092\u6307\u5b9a\u3057\u307e\u3059\uff08\u7701\u7565\u53ef\uff09\u3002<\/li>\n<li>statements&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u5f15\u6570\uff08 <em>condition<\/em> \uff09\u304c\u771f (True) \u3067\u3042\u308b\u9593\uff08 <span class=\"red\"><strong>While<\/strong><\/span> \u306e\u5834\u5408\uff09\u3001\u307e\u305f\u306f\u5f15\u6570\uff08 <em>condition<\/em> \uff09\u304c\u771f (True) \u306b\u306a\u308b\u307e\u3067\uff08 <span class=\"red\"><strong>Until<\/strong><\/span> \u306e\u5834\u5408\uff09\u3001\u7e70\u308a\u8fd4\u3057\u5b9f\u884c\u3055\u308c\u308b\u4efb\u610f\u306e\u884c\u6570\u306e\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3092\u8a18\u8ff0\u3057\u307e\u3059\uff08\u7701\u7565\u53ef\uff09\u3002<\/li>\n<\/ul>\n<br \/><br \/>\n<p class=\"caution3\">\u3010\u69cb\u6587 1\u3011\u306f\u3001<em>statements<\/em> \u3092\u5b9f\u884c\u3059\u308b\u524d\u306b <em>condition<\/em> \u3092\u30c1\u30a7\u30c3\u30af\u3057\u3001\u3010\u69cb\u6587 2\u3011\u306f\u3001<em>statements<\/em> \u3092\u5b9f\u884c\u5f8c\u306b <em>condition<\/em> \u3092\u30c1\u30a7\u30c3\u30af\u3057\u307e\u3059\u3002\u3088\u3063\u3066\u3010\u69cb\u6587 2\u3011\u306e\u5834\u5408\u3001\u6700\u4f4e1\u56de\u306f <em>statements<\/em> \u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\uff08<a href=\"#vba_sample\"> \u21d2 sample_DoLoop02 \u306e\u4f8b <\/a>\uff09\n<\/p>\n<p class=\"caution3\">\u5f15\u6570 <em>condition<\/em> \u306e\u5024\u304c <strong>Null \u5024<\/strong>\u306e\u5834\u5408\u3001\u5f15\u6570 <em>condition<\/em> \u306f\u3001<strong>\u507d (False)<\/strong> \u3067\u3042\u308b\u3068\u307f\u306a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p class=\"caution3\"><strong>Do&#8230;Loop \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8<\/strong> \u304b\u3089\u629c\u3051\u51fa\u3059\u5225\u306e\u65b9\u6cd5\u306b\u3001<span class=\"red\"><strong>Exit Do \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8<\/strong><\/span> \u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u307e\u305f\u3001<strong>Do&#8230;Loop \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8<\/strong> \u306f\u30cd\u30b9\u30c8 (\u5165\u308c\u5b50) \u69cb\u9020\u306b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u3001\u305d\u306e\u5834\u5408\u306b Exit Do \u304c\u5b9f\u884c\u3055\u308c\u305f\u5834\u5408\u306f\u3001\u305d\u306e Exit Do \u3092\u56f2\u3093\u3067\u3044\u308b <strong>1 \u756a\u5185\u5074\u306e\u30eb\u30fc\u30d7<\/strong>\u304b\u3089\u629c\u3051\u51fa\u3057\u307e\u3059\u3002<\/p>\n<p class=\"caution7\">\u3082\u3057\u7121\u9650\u30eb\u30fc\u30d7\u306e\u72b6\u614b\u306b\u9665\u3063\u3066\u3057\u307e\u3063\u305f\u5834\u5408\u306f\u3001<span class=\"red\"><strong>[ECS] \u30ad\u30fc<\/strong><\/span>\u3092\u62bc\u3057\u7d9a\u3051\u308b\u304b\u3001\u305d\u308c\u3067\u623b\u3089\u306a\u3044\u5834\u5408\u306f\u3001<span class=\"red\"><strong>[Ctrl] + [Alt] + [Delete]<\/strong><\/span> \u3092\u62bc\u3057\u3066 Windows \u306e\u30bf\u30b9\u30af\u30de\u30cd\u30fc\u30b8\u30e3\u30fc\u3092\u8868\u793a\u3057\u3066\u3001Excel \u3092\u5f37\u5236\u7d42\u4e86\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<\/div>\n<br \/><br \/>\n<h2>Do&#8230;Loop \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u306e\u4f7f\u7528\u4f8b<\/h2>\n<div class=\"m30-l\">\n<h3 id=\"vba_sample\">VBA\u30bd\u30fc\u30b9\u4f8b<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"Do...Loop \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u4f8b\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\n'Until \u3092\u4f7f\u3063\u305f\u4f8b\r\nSub sample_DoLoop01()\r\n\r\n    Dim num\r\n    Dim cnt\r\n    \r\n    num = 1\r\n    cnt = 0\r\n    \r\n    Do Until num > 100\r\n    \r\n        If cnt = 10 Then Exit Do\r\n        \r\n        num = num * 6\r\n        cnt = cnt + 1\r\n        \r\n    Loop\r\n    \r\n    MsgBox \"num:\" & num & Chr(13) & cnt & \"\u56de\u3000\u30eb\u30fc\u30d7\u3057\u307e\u3057\u305f\"\r\n\r\nEnd Sub\r\n\r\n'While \u3092\u4f7f\u3063\u305f\u4f8b\r\nSub sample_DoLoop02()\r\n    \r\n    Dim cnt1, cnt2\r\n    Dim num\r\n    \r\n    num = 0\r\n    cnt1 = 0\r\n    \r\n    Do While num > 0\r\n        \r\n        num = num - 5\r\n        cnt1 = cnt1 + 1\r\n    \r\n    Loop\r\n    \r\n    num = 0\r\n    cnt2 = 0\r\n    \r\n    Do\r\n        \r\n        num = num - 5\r\n        cnt2 = cnt2 + 1\r\n    \r\n    Loop While num > 0\r\n    \r\n    \r\n    MsgBox \"cnt1:\" & cnt1 & Chr(13) _\r\n    & \"cnt2:\" & cnt2\r\n    \r\n\r\nEnd Sub\r\n\r\n'\u4ee5\u4e0b\u306e\u5834\u5408\u306f\u300cExit Do\u300d\u3092\u4f7f\u7528\u3057\u306a\u3044\u3068\u7121\u9650\u30eb\u30fc\u30d7\u306b\u306a\u308a\u307e\u3059\r\nSub sample_DoLoop03()\r\n\r\n    Dim cnt\r\n\r\n    Do\r\n        cnt = cnt + 1\r\n\r\n        If cnt = 5 Then Exit Do\r\n    Loop\r\n\r\n    MsgBox cnt\r\n\r\nEnd Sub\r\n\r\n\r\n\r\n\u3000\r\n<\/pre>\n<br \/>\n<h3>\u5b9f\u884c\u7d50\u679c<\/h3>\n<p>\u30fbsample_DoLoop01 \u306e\u7d50\u679c<br \/>\n<a href=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/03\/do_loop01.jpg?ssl=1\" rel=\"lightbox[955]\"><img loading=\"lazy\" src=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/03\/do_loop01.jpg?resize=181%2C196&#038;ssl=1\" alt=\"Do Until...Loop\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u4f8b\" width=\"181\" height=\"196\" class=\"alignnone size-full wp-image-964\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>\u30fbsample_DoLoop02 \u306e\u7d50\u679c<br \/>\n<a href=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/03\/do_loop02.jpg?ssl=1\" rel=\"lightbox[955]\"><img loading=\"lazy\" src=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/03\/do_loop02.jpg?resize=154%2C196&#038;ssl=1\" alt=\"Do While...Loop \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u4f8b\" width=\"154\" height=\"196\" class=\"alignnone size-full wp-image-965\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>\u30fbsample_DoLoop03 \u306e\u7d50\u679c<br \/>\n<a href=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/03\/do_loop03.jpg?ssl=1\" rel=\"lightbox[955]\"><img loading=\"lazy\" src=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/03\/do_loop03.jpg?resize=154%2C178&#038;ssl=1\" alt=\"Do...Loop \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u4f8b\" width=\"154\" height=\"178\" class=\"alignnone size-full wp-image-966\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<br \/>\n<\/div>\n<br \/><br \/>\n","protected":false},"excerpt":{"rendered":"<p>Do&#8230;Loop \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u306e\u4f7f\u3044\u65b9 \u3010\u69cb\u6587 1\u3011 Do [ Wh &#8230; <\/p>\n","protected":false},"author":1,"featured_media":964,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"amp_status":"","spay_email":"","jetpack_publicize_message":"\u30d6\u30ed\u30b0\u3092\u66f4\u65b0\u3057\u307e\u3057\u305f\u3002"},"categories":[48],"tags":[55,54,53,38,49,56],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/03\/do_loop01.jpg?fit=181%2C196&ssl=1","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4Ye9i-fp","_links":{"self":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/955"}],"collection":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/comments?post=955"}],"version-history":[{"count":12,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/955\/revisions"}],"predecessor-version":[{"id":978,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/955\/revisions\/978"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media\/964"}],"wp:attachment":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media?parent=955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/categories?post=955"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/tags?post=955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}