{"id":149,"date":"2007-12-30T21:31:36","date_gmt":"2007-12-31T04:31:36","guid":{"rendered":"http:\/\/members.crystalreportsbook.com\/crystal-reports-xi\/714-while-and-do-loops\/"},"modified":"2007-12-30T21:31:36","modified_gmt":"2007-12-31T04:31:36","slug":"714-while-and-do-loops","status":"publish","type":"post","link":"http:\/\/www.crystalreportsonlinetraining.com\/training\/714-while-and-do-loops\/","title":{"rendered":"7.14 While and Do Loops"},"content":{"rendered":"<h2>While and Do Loops<\/h2>\n<p>The While and Do loops all have the standard syntax. The While keyword is used to continue looping as long as the condition evaluates to True. The While block is terminated with a Wend statement. The Do loops are terminated with a Loop statement. The Until keyword is used to continue looping when a condition evaluates to False. You can exit a Do loop with an Exit Do statement.<\/p>\n<p>Crystal syntax uses parentheses to define the code block.<\/p>\n<p>Code template for While \u2026  Do:<\/p>\n<p>         <code_Single>While true_condition Do<\/code_Single><br \/>\n         <code_Single>(<\/code_Single><br \/>\n         <code_Single>&#8230;code&#8230;<\/code_Single><br \/>\n         <code_Single>)<\/code_Single><\/p>\n<p>Code template for Do..While:<\/p>\n<p>         <code_Single>Do<\/code_Single><br \/>\n         <code_Single>(<\/code_Single><br \/>\n         <code_Single>&#8230;code&#8230;<\/code_Single><br \/>\n         <code_Single>) While true_condition<\/code_Single><\/p>\n<p>The next example takes an array of names (populated elsewhere in the program) and uses a While loop to combine the names into a single string.<\/p>\n<p>         <code_Single>\/\/Combine all names from an array into a single string<\/code_Single><br \/>\n         <code_Single>Global StringVar Names;<\/code_Single><br \/>\n         <code_Single>StringVar NameList;<\/code_Single><br \/>\n         <code_Single>NumberVar Counter := 1;<\/code_Single><br \/>\n         <code_Single>While Names[Counter] <> &#8220;&#8221; Do<\/code_Single><br \/>\n         <code_Single>(<\/code_Single><br \/>\n         <code_Single>NameList := NameList &amp; Names[Counter] &amp; &#8221; &#8220;;<\/code_Single><br \/>\n         <code_Single>Counter := Counter + 1;<\/code_Single><br \/>\n         <code_Single>);<\/code_Single><br \/>\n         <code_Single>\/\/Return the name list<\/code_Single><br \/>\n         <code_Single>NameList;<\/code_Single><\/p>\n","protected":false},"excerpt":{"rendered":"<p>While and Do Loops The While and Do loops all have the standard syntax. The While keyword is used to continue looping as long as the condition evaluates to True. The While block is terminated with a Wend statement. The Do loops are terminated with a Loop statement. The Until keyword is used to continue [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,1],"tags":[],"class_list":["post-149","post","type-post","status-publish","format-standard","hentry","category-chapter-7-programming-with-crystal-syntax","category-crystal-reports-xi","entry"],"_links":{"self":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/149","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/comments?post=149"}],"version-history":[{"count":0,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/149\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/media?parent=149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/categories?post=149"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/tags?post=149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}