Iterative Statement In Programming Language

Great Essays
Overview:
Iterative statement is the programming language design feature that is going to be discussed. And the programming languages for which the feature is discussed are C, Perl, Prolog and Common Lisp.
In C the three pre-defined iterative statements are for, while and do while.
In Perl the pre-defined iterative statements include for, foreach, while, do while and until.
In Common Lisp the pre-defined iterative statements include do, dotimes, dolist and loop (includes for and while)
In Prolog there are no iterative statements. Since Prolog is a fact and rule based language and the programmers are allowed to provide with the info what needs to be achieved rather than how it needs to be achieved there are no iterative statements in Prolog.
…show more content…
• In do while loop statements are executed without any condition check for first iteration and are executed only if the condition is true for the successive iterations.
• until is used to iterate statements until a particular expression or condition is evaluated to true.
• foreach and dolist are used to iterate statements over an array or a list. Both the loops can have a variable whose value represents an element of the list for each iteration.
• dotimes is similar to dolist but instead of iterating over the values of a list, it iterates the value of a variable up to a specified count. The value of the variable ranges from 0 to specified count – 1.
• do is a flexible iterator construct and can be used to replace dotimes and dolist. Unlike dotimes and dolist which provides only one loop variable do supports an arbitrary number of loop variables.
• loop is an iterator when coupled with constructs like when, for, while, finally… called as extended loop and loop without them is called a simple loop. A simple loop is an infinite loop whereas extended loop can be made as a finite loop.
Syntax:
Syntax for iterative statements in
…show more content…
clause2(Y) :- clause2(X).

Semantics:
Semantics of Iterative statements in C: for: The loop commences by initializing the loop variable. The condition is first checked before executing the statements. After each iteration the increment/ decrement of the loop variable done after which the condition is checked. The loop terminates once the condition is evaluated to false. while: The loop starts by checking the condition/expression and continues only if the condition/expression is evaluated to true. Then the statements in the while block is executed. The iteration continues until the expression/condition is evaluated to false. dowhile: The loop starts by executing the statements first and then checking the expression/condition the loop continues to execute the statements for each iteration until the expression is evaluated to true.
Semantics of Iterative statements in Perl: The semantics of for, while and dowhile in Perl is same as that of C. Perl has two other iterative statements such as foreach and until. foreach: foreach in Perl iterates through the values of the list provided. It has an optional loop variable whose value is equal to the value in the list for which the iteration occurs. The statements of the loop are executed for each iteration. The loop terminates once all the values in the list are

Related Documents

  • Improved Essays

    1. I agree that increasing the router memory to infinite cannot control congestion because even if routers have an infinite amount of memory, congestion gets worse, because by the time packets reach to the front of the queue, they have already timed out (repeatedly), and duplicates have been sent. 2. Flow Control vs Congestion Control It ensures that the sender only sends what the receiver can handle.…

    • 617 Words
    • 3 Pages
    Improved Essays
  • Improved Essays

    Property Formalization The model checker SMV utilizes the fanning time worldly rationale CTL (Computation .Tree Logic) for the detail of properties. A prologue to this rationale can be found in [4]; here we simply give a couple of illustrations. We accept that φ, ψ are a propositional expression over the variables that characterize the framework's state space. At that point every now and again utilized CTL colloquialisms are: • AGφ is genuine, iff φ holds invariantly for all executions of the framework.…

    • 869 Words
    • 4 Pages
    Improved Essays
  • Improved Essays

    The different data types available for programming are String, Integer, Single, Double, Boolean and Date. - Data Type: String  Use of String: A String can be used as a form of a character e.g. “a” or a string of characters e.g. “abcdefg”. It can be any type of text e.g. “Hello World!”. • Alphabetic – A to Z, a to z, space • Special characters - £$%& • Numbers that are not used for calculations.…

    • 841 Words
    • 4 Pages
    Improved Essays
  • Improved Essays

    Pt1420 Unit 8

    • 925 Words
    • 4 Pages

    Eventually the program would get down to the innermost parentheses and return that answer up a level so that instance can solve its…

    • 925 Words
    • 4 Pages
    Improved Essays
  • Improved Essays

    Vocabulary: Study Guide

    • 833 Words
    • 4 Pages

    Vocabulary 1. Inoculum: a material used for inoculation. 2. Loop (the tool): A wire made into a loop to assist in picking up inoculum from a culture of microorganisms. The loop is also used in the process of cultivating microbes by transferring inoculum for streaking.…

    • 833 Words
    • 4 Pages
    Improved Essays
  • Improved Essays

    Data Type Description and example use **You must provide an example of what each data type could be used for** String A data type used in programmings such as an integer and floating point unit, but is used to represent text rather than numbers. • I bought 3 CD’s which were from 3 different artists. It shows that I bought it from 3 different people. • If (Option 1==Option 2) If the values are the same, then it is true.…

    • 902 Words
    • 4 Pages
    Improved Essays
  • Improved Essays

    Pt1420 Unit 6 Ada

    • 243 Words
    • 1 Pages

    Fortran program loop integer :: j integer :: k integer :: i j = -20 do k = ((j*2) – 1) , 10 i = 3*k – 1 end do end program loop ada procedure Loop_Code is j, k, I : INTEGER; j = -20; k = j*2 - 1 begin while k y + 2 is a lambda function taking input y and adding 2 to it. In common lisp they are declared as “ #’(lambda(argument)(+argument argument))“. In fact ,lisp is one of the first programming languages to have implemented lambda functions. In Standard ML the declaration is as follows, “ fn argument => argument + argument” .…

    • 243 Words
    • 1 Pages
    Improved Essays
  • Improved Essays

    Pt1420 Unit 1 Study Guide

    • 607 Words
    • 3 Pages

    Testing is one of the most important parts of software development life cycle. It is an element of software quality assurance and can be described as a process of running a program in such a manner as to uncover any errors. Testing also demonstrates that software functions appear to be working according to specifications, that behavioral and performance requirements appear to have been met. That test will be carried out when the system is complete. In this chapter, I test my simulation software with testing method.…

    • 607 Words
    • 3 Pages
    Improved Essays
  • Improved Essays

    Theme Of 10 Mary Street

    • 751 Words
    • 4 Pages

    It also features an in-depth description of his childhood in relation to living at 10 Mary Street. Also included in this poem is description of the connection Peter has with his parents. A reoccurring theme of time is present throughout the poem 10 Mary Street. This is shown with the constant repetition of the line “For nineteen years”. The use of this repetition allow us to engage as to how long Peter had stayed at the house as well as to reinforce the long period of time.…

    • 751 Words
    • 4 Pages
    Improved Essays
  • Superior Essays

    Note and notice signposts 1.tough questions-"why, but why would I bless him (Wiesel 67)? " 2. Contrast and contradict- stops talking about the Holocaust and talks about the future which is happy. ( Wiesel 53) 3. Again and again- they give warnings about what's going to happen ( Wiesel 27)".…

    • 941 Words
    • 4 Pages
    Superior Essays
  • Improved Essays

    Dan Hurley's Obstacle

    • 384 Words
    • 2 Pages

    “Feel the burn!” That was Jane Fonda in 1982, exhorting the viewers of her first-of-its-kind workout video to engage in an exotic pursuit called exercise. In her striped leotard and legwarmers, Fonda led the charge against the generally held opinion that exercise was a weird waste of time. (In those days, lifting weights was for Charles Atlas aspirants, and jogging was for quirky “health nuts.”) The tireless exertions of Fonda — and of tiny-shorted Richard Simmons and toothy Judi Sheppard Missett, the founder of Jazzercise — were ultimately wildly successful, making what was then an eccentric choice into what is now practically an obligation.…

    • 384 Words
    • 2 Pages
    Improved Essays
  • Improved Essays

    In today’s society there are many things that impact our views on people and their race. One way that impacts our judgment is implicit attitudes. These attitudes are defined as an assessment towards objects or people that occurs without being consciously aware. To help measure how much implicit attitudes affect people’s judgment three professors: Anthony Greenwald, Mahzarin Banaji, and Brian Nosek co-created the Implicit Association Test.…

    • 618 Words
    • 3 Pages
    Improved Essays
  • Improved Essays

    Funes The Memorious

    • 1201 Words
    • 5 Pages

    Funes tries to make communication easier by creating more specific terms so others can pinpoint exactly what he refers to. However, his attempts create terms so specific, no one else can understand him. An example of one of his creations is a numerical system where he assigns specific words to specific numbers.…

    • 1201 Words
    • 5 Pages
    Improved Essays
  • Improved Essays

    Instructional Strategies

    • 839 Words
    • 4 Pages

    Describe your strategy for transitioning into the next part of lesson. My foldable looks just like yours and as we move through the PowerPoint if you do not know where we are on the foldable just ask or refer to mine, back here. When you are done filling in the blanks for that page put your pencil down. Instructional Procedures/ Learning Tasks:…

    • 839 Words
    • 4 Pages
    Improved Essays
  • Improved Essays

    Divide and Conquer Strategies: Divide and conquer is an algorithm which design paradigm based on multi-branched recursion. This designed paradigm consists of following phases: 1) Break the problem (divide): Breaking the problem into several sub-problems that are smaller in size. 2) Solve the sub problem(conquer) : Solve the sub-problem recursively .…

    • 718 Words
    • 3 Pages
    Improved Essays