Some Common Issues: Iteration

Slides:



Advertisements
Similar presentations
LOOPS Loops are lines of code that can be run more than one time. Each time is called an iteration and in for loops there is also an index that is changing.
Advertisements

1 ln(x) e x Approximating functions Elementary Functions.
Write a function to calculate the cubic function: y = 4x 3 + 2x 2 –5x – 4 The function should return y for any given value of x. Question One #include.
Test practice Multiplication. Multiplication 9x2.
Neal Stublen Loop Structure  Sometimes it’s useful to repeat yourself  The same actions need to occur more than once  Ensures.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
Lists CMSC 201. Overview Today we will learn about: For loops.
CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
Flow Charting, Structured English and PseudoCode
True BASIC Ch. 6 Practice Questions. What is the output? PRINT X LET X = -1 PRINT X FOR X = 4 TO 5 STEP 2 PRINT X NEXT X PRINT X END.
Dueling Algorithm. Data Structures List of potential candidates R = rightmost element of that list N = new element RN.
Linux/Bash Commands Damian Gordon. ls List all the visible files in the current folder.
Python: Modularisation Damian Gordon. Modularisation Remember the prime checker program:
Fibonacci Numbers Damian Gordon. Fibonacci Numbers.
Iteration: WHILE Loop Damian Gordon. WHILE Loop Consider the problem of searching for an entry in a phone book with only SELECTION:
AE1205 Programming Python Quiz: so how do we generate Numbers 1 to 10? range( ) Numbers 5,10,15,20,25 to 100? range( ) Numbers 20,18,16, to 0? range( )
Searching Damian Gordon. Google PageRank Damian Gordon.
Programming Training Main Points: - Problems with repetitions. - Discuss some important algorithms.
ANALYSIS AND ALGORITHM DESIGN - IV. Repeat statements/looping/counting/iterations It is often necessary to repeat certain parts of a program a number.
Sorting: Optimising Bubblesort Damian Gordon. Sorting: Bubble Sort If we look at the bubble sort algorithm again:
Counter-Controlled Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Data Structures: Arrays Damian Gordon. Arrays Imagine we had to record the age of everyone in the class, we could do it declaring a variable for each.
Python: Arrays Damian Gordon. Arrays In Python arrays are sometimes called “lists” or “tuple” but we’ll stick to the more commonly used term “array”.
Modularisation Damian Gordon. Modularisation Let’s imagine we had code as follows:
Structured Programming Constructs March, 2011Copyright Yvette Francis.
Python: Sorting - Bubblesort Damian Gordon. Sorting: Bubblesort The simplest algorithm for sort an array is called BUBBLE SORT. It works as follows for.
Sorting: Selection Sort Damian Gordon. Sorting: Selection Sort OK, so we’ve seen a way of sorting that easy for the computer, now let’s look at a ways.
For Loops CMSC 201. Overview Today we will learn about: For loops.
Prime Numbers Damian Gordon. Prime Numbers So let’s say we want to express the following algorithm: – Read in a number and check if it’s a prime number.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
Data Structures: Multi-Dimensional Arrays Damian Gordon.
For loop. Exercise 1 Write a program to have the user input three (3) numbers: (f)rom, (t)o, and (i)ncrement. Count from f to t in increments of i, inclusive.
Recursion Damian Gordon. Recursion Recursion: Factorial Recursion is a feature of modularisation, when a module can call itself to complete a solution.
Computer Program Flow Control structures determine the order of instruction execution: 1. sequential, where instructions are executed in order 2. conditional,
Python: Iteration Damian Gordon. Python: Iteration We’ll consider four ways to do iteration: – The WHILE loop – The FOR loop – The DO loop – The LOOP.
Learning Objectives 1. Understand how the Small Basic Turtle operates. 2. Be able to draw geometric patterns using iteration.
Computational Astronomy 제 5 장 프로그래밍 기초 전산천문학 봄.
Recursion Damian Gordon. Recursion Factorial Fibonacci Decimal to Binary conversion Travelling Salesman Problem Knight’s Tour.
Iteration: FOR, DO, LOOP Loop Damian Gordon. FOR Loop The FOR loop does the same thing as a WHILE loop but is easier if you are using the loop to do a.
Selection: CASE Statement Damian Gordon. Selection As well as the IF Statement, another form of SELECTION is the CASE statement.
Introduction to Python
Drought in Africa - Smart Irrigation System Example Program
Boolean Logic Damian Gordon.
Chapter (3) - Looping Questions.
Python: Algorithms Damian Gordon.
Programming Training Main Points: - Problems with repetitions.
the captured notes and redid - hopefully it all works.
Hmjngj jxhngh.
Simple Statistics on Arrays
Simple Statistics on Arrays
Module 4 Loops and Repetition 2/1/2019 CSE 1321 Module 4.
Sorting Damian Gordon.
Module 4 Loops and Repetition 4/7/2019 CSE 1321 Module 4.
CHAPTER 4 Iterative Structure.
Module 4 Loops and Repetition 4/4/2019 CSE 1321 Module 4.
Module 4 Loops and Repetition 4/15/2019 CSE 1321 Module 4.
Some Common Issues: Print, Maths, Variables
Python: Sorting – Selection Sort
Input a number and print its table, using FOR loop.
Introduction to Computer Science
Print the following triangle, using nested loops
Some Common Issues: Common Algorithms
For Loops Pages
Topic: Loops Loops Idea While Loop Introduction to ranges For Loop
Wrapup which is the document write that says the end.
LOOP Basics.
Arrays: Iteration Working through an array algorithmically.
Introduction to Python
PseudoCode Damian Gordon.
Presentation transcript:

Some Common Issues: Iteration Damian Gordon

WHILE Loops

# PROGRAM Print1To5: a = 1 while a # PROGRAM Print1To5: a = 1 while a != 6: # DO print(a) a = a + 1 # ENDWHILE; # END.

# PROGRAM Print1To5: a = 1 while a # PROGRAM Print1To5: a = 1 while a != 6: # DO print(a) a = a + 1 # ENDWHILE; # END. >> 1 2 3 4 5

FOR Loops

# PROGRAM Print1To5For: for a in range(1,6): # DO print(a) # ENDFOR; # END.

# PROGRAM Print1To5For: for a in range(1,6): # DO print(a) # ENDFOR; # END. >> 1 2 3 4 5

Printing Multiple Values FOR Loops Printing Multiple Values

# PROGRAM Print1To5For: for a in range(1,6): # DO print(a, a+1) # ENDFOR; # END.

# PROGRAM Print1To5For: for a in range(1,6): # DO print(a, a+1) # ENDFOR; # END. >> 1 2 2 3 3 4 4 5 5 6

# PROGRAM Print1To5For: for a in range(1,6): # DO print(a, a+1, a+10) # ENDFOR; # END.

# PROGRAM Print1To5For: for a in range(1,6): # DO print(a, a+1, a+10) # ENDFOR; # END. >> 1 2 11 2 3 12 3 4 13 4 5 14 5 6 15

Incrementing by different values FOR Loops Incrementing by different values

# PROGRAM Print-For: for a in range(1,6,1): # DO print(a) # ENDFOR; # END.

# PROGRAM Print-For: for a in range(1,6,1): # DO print(a) # ENDFOR; # END.

# PROGRAM Print-For: for a in range(1,6,1): # DO print(a) # ENDFOR; # END. >> 1 2 3 4 5

# PROGRAM Print-For: for a in range(1,6,2): # DO print(a) # ENDFOR; # END.

# PROGRAM Print-For: for a in range(1,6,2): # DO print(a) # ENDFOR; # END. >> 1 3 5

# PROGRAM Print-For: for a in range(1,6,3): # DO print(a) # ENDFOR; # END.

# PROGRAM Print-For: for a in range(1,6,3): # DO print(a) # ENDFOR; # END. >> 1 4