1 / 12

Repetition Structures

Repetition Structures. Dr. John P. Abraham UTPA. While End While. Only enters the loop if condition yields true Choose LCV Initialize LCV Setup condition for looping statements Change value of LCV. Module Module1 Dim rate As Double Dim principle As Double

nicollej
Download Presentation

Repetition Structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Repetition Structures Dr. John P. Abraham UTPA

  2. While End While • Only enters the loop if condition yields true • Choose LCV • Initialize LCV • Setup condition for looping • statements • Change value of LCV

  3. Module Module1 Dim rate As Double Dim principle As Double Dim period As Integer Dim dinterest, yinterest As Double Dim i As Integer = 1 Sub Main() rate = 0.07 principle = 10000.0 period = 2 'years Console.WriteLine("Beginning Principle: " & principle) While i <= period * 365 dinterest = principle * rate / 365 yinterest = yinterest + dinterest principle = principle + dinterest If i Mod 365 = 0 Then Console.WriteLine("Interest for the year: " & yinterest) Console.WriteLine("Principle at the year End: " & principle) yinterest = 0 Console.ReadKey() End If i = i + 1 End While End Sub End Module

  4. Do while ..loop Similar to while..end Do Until..Loop Enters the loop if condition yields false Loop termination condition is different than the previous two Other pretest loops

  5. Counter controlled A variable keeps track of number of time the loop should be executed. The number of executions are known before loop begins to execute. For-next is a counter controlled You provide LCV initial count, ending count, increment. Condition checking and incrementing is done automatically Sentinel controlled – sentinel value, events etc. Counter controlled & Sentinel controlled loops

  6. Inner loop Inner loop executes for every instance of outer loop Outer loop Nested Repetition statements

  7. Executed at least once Do..Loop While Do..Loop Until Termination condition is different than do..loop while Post test loops

  8. Not recommended Can alter program flow of control Exit statement will break out of the loop Using Exit in Repetition Statements

  9. = Equal to > More than < Less Than >= More than and equal <= Less than and equal <> Not Equal to  Logical Oper Conditional (assignment) Operators

  10. And :Both sides must be true AndAlso :If the left side is false does not check the right side Or :One side or other must be true OrElse : If the left side is true does not check the right side Xor :One side or other must be true but not both Not :Negates truth Logical Operators

  11. Allows you to make multiple references to the same object in a concise manner. Suppose you have: GRADEBOOK.DISPLAYMESSAGE() GRADEBOOK.INPUTGRADES() GRADEBOOK.DISPLAYGRADEREPORT() You can do this: With gradebook .displaymessage(0 .inputgrades() .displaygradeReport() End with Using With statement

  12. Using continue in Repetiton statements Skips the remaining statements in the loop body of the repetiton and causes control to proceed to the next iteration of the loop. Example While counter <10 counter +=1 If counter = 5 then Continue while ‘skips to next iteration of loop End if Console.write (“{0}”, counter) End while. Display 1 2 3 4 6 7 8 9 10

More Related