Coding Design Tools Rachel Gauci. Task: Counting On Create a program that will print out a sequence of numbers from "1" to a "number entered”. Decision’s.

Slides:



Advertisements
Similar presentations
Topic 8 :PROGRAMMING 8.4 Use of control structure Learning Outcome : Write a program segment by using appropriate control structure.
Advertisements

Week 5: Loops 1.  Repetition is the ability to do something over and over again  With repetition in the mix, we can solve practically any problem that.
Introduction to working with Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
Introduction to Computers and Programming Lecture 8: More Loops New York University.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
Designing Algorithms Csci 107 Lecture 3. Designing algorithms Last time –Pseudocode –Algorithm: computing the sum 1+2+…+n –Gauss formula for 1+2+…+n Today.
Introduction to Computers and Programming More Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
COMP 110 Introduction to Programming Mr. Joshua Stough September 24, 2007.
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
Python quick start guide
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
HOMEWORK REVIEW This is an if else statement layout if (condition) { code to be executed if condition is true; } else { code to be executed if condition.
Chapter 5 Repetition or loop structure. What is repetition or loop? repeat the execution of one or a group (block; instruction enclosed in a pair of braces)
Structured Program Development Outline 2.1Introduction 2.2Algorithms 2.3Pseudo code 2.4Control Structures 2.5The If Selection Structure 2.6The If/Else.
By the end of this session you should be able to...
Coding Design Tools Rachel Gauci. What are Coding Design Tools? IPO charts (Input Process Output) Input- Make a list of what data is required (this generally.
1 Loops. 2 Topics The while Loop Program Versatility Sentinel Values and Priming Reads Checking User Input Using a while Loop Counter-Controlled (Definite)
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
USING UNITY JAVASCRIPT. CONVENTIONS AND SYNTAX IN JAVASCRIPT Case Sensitivity All keywords like var or function must be in lowercase. All variable names,
Lecture 4: Calculating by Iterating. The while Repetition Statement Repetition structure Programmer specifies an action to be repeated while some condition.
Chapter 5: Control Structures II J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
Lecture 4: C/C++ Control Structures Computer Programming Control Structures Lecture No. 4.
Structured Program Development Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010.
REPETITION STATEMENTS - Part2 Structuring Input Loops Counter-Controlled Repetition Structure Sentinel-Controlled Repetition Structure eof()-Controlled.
Chapter 7 Problem Solving with Loops
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
The ‘while’ loop ‘round and ‘round we go.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
Introduction to Computers and Programming Lecture 7:
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
Intro to Loops 1.General Knowledge 2.Two Types of Loops 3.The WHILE loop 1.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
CS 101 – Oct. 7 Solving simple problems: create algorithm Structure of solution –Sequence of steps (1,2,3….) –Sometimes we need to make a choice –Sometimes.
CC213 Programming Applications Week #2 2 Control Structures Control structures –control the flow of execution in a program or function. Three basic control.
Computer Programming 12 Lesson 6 – Loop structure By: Dan Lunney.
Selection Using IF THEN ELSE CASE Introducing Loops.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (while) Outline 3.7The While Repetition.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 23, 2005 Lecture Number: 11.
Topic : While, For, Do-While Loop Guided By : Branch : Batch :
REPETITION CONTROL STRUCTURE
while Repetition Structure
Chapter 5: Control Structures II
Java for Beginners.
Lecture 4 - Loops UniMAP EKT120 Sem 1 08/09.
Week 4 – Repetition Structures / Loops
Repetition-Counter control Loop
Ch 7: JavaScript Control Statements I.
JavaScript: Control Statements.
ALGORITHMS AND FLOWCHARTS
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Java for Beginners University Greenwich Computing At School DASCO
Structured Program
Chapter 3 - Structured Program Development
3 Control Statements:.
Chapter 3 - Structured Program Development
Computing Fundamentals
EPSII 59:006 Spring 2004.
Repetition Statements (Loops) - 2
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Presentation transcript:

Coding Design Tools Rachel Gauci

Task: Counting On Create a program that will print out a sequence of numbers from "1" to a "number entered”. Decision’s need to be made before moving onto designing… 1.What does the task want? 2.What type of script would best fit the requirements (e.g. IF ELSE statement, FOR/WHILE LOOPS etc.)

Example- Pseudocode Pseudocode’s used to point out the actions in your script. How is this done? You write your script in an informal way, leaving out ; () {} etc. then you put the main words in capitals/ bold making them stand out. Ideally we want to write what we want a particular part of code to look like E.G. #pragma strict var age= 22; function Start() { if (age >= 18) { Debug.Log ("You Qualify"); } else { Debug.Log("You do not qualify"); } } function Update() { } IF AGE >= 18 THEN PRINT “You Qualify” ELSE PRINT “You do not qualify” END IF

More Pseudocode puting/cs/programming/good- practices/p/pseudo-code this is for drawings and in its simplest form explains pseudo code and why we use it. However this demonstration is not how I want it set out. ntro/pseudocode2js-v02.pdf Set total to zero Set grade counter to one WHILE grade counter is less than or equal to ten Input the next grade ADD the grade into the total Set the class average to the total divided by ten PRINT class average. START Program Enter two numbers A, B Add the numbers together PRINT sum END program

Example- IPO charts #pragma strict var age= 22; function Start() { if (age >= 18) { Debug.Log ("You Qualify"); } else { Debug.Log("You do not qualify"); } } function Update() { } INPUTPROCESSOUTPUT AgeUser puts in age -- it is determined whether the person is 18 or > < Results whether “You Qualify” or “You do not Qualify”

LOOPS FOR LOOPS- the loop is repeated a "specific" number of times, determined by the program or the user. The loop "counts" the number of times the body will be executed. This loop is a good choice when the number of repetitions is known, or can be supplied by the user. (set initial variable; condition; action on the variable) for (var i : int = 0 ; i < numEnemies ; i++) While Loops: The loop must repeat until a certain "condition" is met. If the "condition" is FALSE at the beginning of the loop, the loop is never executed. The "condition" may be determined by the user at the keyboard. The "condition" may be a numeric or an alphanumeric entry. This is a good, solid looping process with applications to numerous situations. while (condition/expression) { Statement/s to be executed if expression is true }

The for loop is used to repeat a section of code known number of times. Sometimes it is the computer that knows how many times, not you, but it is still known. Some examples: Unknown number of times: "Ask the User to Guess a pre-determined number between 1 and 100". You have no way of knowing how many guesses it will take. "Randomly look in an array for a given value." You have no way of knowing how many tries it will take to find the actual value. Note: this is a made-up example, because you would never randomly look into an array to find a value. You would always start at the front of the array and look one element at a time until you found the item or got to the end of the array. Known number of times: Compute the average grade of the class. While you (the programmer) might not know how many grades exist in the class, the computer will know. Usually this is accomplished by using the "length" function on an array. Print the odd numbers from 1 to Search a list (array) of numbers for the biggest grade. Again, the computer "knows" how many grades there are, so a for loop is appropriate.

Design solution 1. Create an IPO chart 2. Create a Pseudocode INPUTPROCESSOUTPUT NumberUsing input (variable) loop over the input until the condition is satisfied (<=) Loop “Count” input BEGIN Declare input FOR start variable = 1, variable <= input, Add 1 PRINT "Count:” input + 1 END

Code solution #pragma strict var x= 12; function Start () { for (var i = 1; i <= x; i++) { Debug.Log ("Count:" + i); } } function Update () { }

How can we test the user’s input? In Unity, when you create a variable in your script (outside the LOOP statement) you give it an initial value. When you look at your script in the inspector view, it will give you the opportunity to edit your variable and press play to see the result.

If, Else if  if statement - executes some code only if a specified condition is true  if...else statement - executes some code if a condition is true and another code if the condition is false  if...elseif....else statement - selects one of several blocks of code to be executed If (condition) { statement } Else if (other condition) { statement }