ITC 240: Web Application Programming

Slides:



Advertisements
Similar presentations
CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
Advertisements

PHP Conditions MIS 3501, Fall 2014 Jeremy Shafer Department of MIS Fox School of Business Temple University September 11, 2014.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
PHP Functions and Control Structures. 2 Defining Functions Functions are groups of statements that you can execute as a single unit Function definitions.
CS 106 Introduction to Computer Science I 02 / 18 / 2008 Instructor: Michael Eckmann.
Computer Science 1620 Loops.
ITERATIVE CONSTRUCTS: DOLIST Dolist is an iterative construct (a loop statement) consisting of a variable declaration and a body The body states what happens.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
Iteration This week we will learn how to use iteration in C++ Iteration is the repetition of a statement or block of statements in a program. C++ has three.
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Chapter 4 Functions and Control Structures PHP Programming with MySQL.
CS 106 Introduction to Computer Science I 02 / 11 / 2008 Instructor: Michael Eckmann.
Loops – While, Do, For Repetition Statements Introduction to Arrays
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
Computer Programming 1 Repetition. Computer Programming 2 Objectives Repetition structures Study while and do loops Examine for loops A practical example.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
CS 106 Introduction to Computer Science I 09 / 28 / 2007 Instructor: Michael Eckmann.
TODAY’S LECTURE Review Chapter 2 Go over exercises.
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
Lecture 8: Choosing the Correct Loop. do … while Repetition Statement Similar to the while statement Condition for repetition only tested after the body.
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
Class 2Intro to Databases Goals of this class Include & Require in PHP Generating Random Numbers in PHP Arrays – Numerically Indexed and Associative Program.
Chapter 2 Functions and Control Structures PHP Programming with MySQL 2 nd Edition.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
Program Flow Control - Looping Addis Ababa Institute of Technology Yared Semu April 2012.
PHP Constructs Advance Database Management Systems Lab no.3.
L OO P S While writing a program, there may be a situation when you need to perform some action over and over again. In such situation you would need.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Repetition Structures Repetition Structures allow you to write programs that will repeat program steps multiple times. –Also called Loops –Counter controlled.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 5 Looping.
JavaScript, Fourth Edition
ITERATIVE STATEMENTS. Definition Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Loops cause a section of a program to be repeated a certain number of times. The repetition continues while a condition remains true. When a condition.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
1 Standard Version of Starting Out with C++, 4th Brief Edition Chapter 5 Looping.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
IS2802 Introduction to Multimedia Applications for Business Lecture 4: JavaScript, Loops, and Conditional Statements Rob Gleasure
Controlling Program Flow with Looping Structures
Chapter Looping 5. The Increment and Decrement Operators 5.1.
COMP Loop Statements Yi Hong May 21, 2015.
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
Engineering Computing I Chapter 3 Control Flow. Chapter 3 - Control Flow The control-flow of a language specify the order in which computations are performed.
Unit – 3 Control structures. Condition Statements 1.If.…..else :- Has someone ever told you, "if you work hard, then you will succeed"? And what happens.
Looping Increment/Decrement Switch. Flow of Control Iteration/Switch Statements.
CC213 Programming Applications Week #2 2 Control Structures Control structures –control the flow of execution in a program or function. Three basic control.
Today… Preparation for doing Assignment 1. Invoking methods overview. Conditionals and Loops. Winter 2016CMPE212 - Prof. McLeod1.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
© 2004 Pearson Addison-Wesley. All rights reserved October 5, 2007 Arrays ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor:
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 10P. 1Winter Quarter Repetition Structures Lecture 10.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
Loops in Java.
Programming Fundamentals
Arrays, For loop While loop Do while loop
Java Programming Loops
CMPT 102 Introduction to Scientific Computer Programming
A LESSON IN LOOPING What is a loop?
Java Programming Loops
PROGRAM FLOWCHART Iteration Statements.
LOOPING STRUCTURE Chapter - 7 Padasalai
Presentation transcript:

ITC 240: Web Application Programming Subhash Prajapati 04/23/15

Review Array - variable type that can hold many values at a time Indexed Array - arrays with numeric index Associative Array - arrays with named keys Multidimentional Array - arrays within the array

Today Array Exercise Loops

Review Exercise: 6.1 Create students array that would include all the students name in a class [Numeric Indexed Array] Create a states array with state abbreviations as keys [Associative Array] Create students array with marks on different subjects [Multidimensional Array]

unset()/isset() These are two PHP built-in functions to do following: isset() - check whether a variable is set or not (od ) unset() – destroys the variable We can destroy/delete the array element like this: unset ($myArray[2])

Loop We can alter the flow of control using either conditionals or loops Loops: execute a statement(s) over and over. Usually contains: - a start condition - a break condition - change in each iteration

while loop loops through a block of code as long as the specified condition is true

while loop Syntax: while (condition) { // code block to be executed }

while loop example Following loop will iterate 4 times $counter = 1; while ($counter<5) { echo “The counter is: ” . $counter.”<br>”; $counter++; }

Quiz What happens to following code $counter = 0; while ($counter < 1) { echo “The counter is: ” . $counter.”<br>”; $counter--; }

Class Exercise 6.2 Write a program with while loop, which would print following table of squares (styling not required) Number Square Value 1 2 4 3 9 16 5 25 6 36 7 49 8 64 81 10 100

while loop alternative syntax while (expression): // statements goes here endwhile; eg: $i = 0; while ($i<10): echo $i; $i++;

do .. while loop loops through a block of code once, and then repeats the loop for specified condition is true

do .. while loop Syntax: do { // code block to be executed } while (condition);

do .. while loop do { do_work(); } while (condition); is equivalent to while (condition) { }

while vs do .. while loop The difference between do-while and while is that do-while evaluates its expression at the bottom of the loop instead of the top. Therefore, the statements within the do block are always executed at least once.

while example scenario Consider a program which writes some text in a file until file size becomes 5MB. We can use while loop in this scenario like this. while(IsFileSizeLessThan5MB()) { WriteMoreData (); }

do .. while example scenario Let's consider another scenario where we want to take an integer input from user until user has entered a positive number. In this case we will use a do-while loop like this. do { TakeInputFromUser(); } while ($input < 0);

Class Exercise 5.3 Cumulative Sum: write a method (function) with a while loop that computes the sum of first n positive integer. for eg: if you pass 5, it will give 15 (sum of 1+2+3+4+5) hints: Declare a function which will take one argument, the function will return the sum Inside the function, write a while loop which will iterate n number of time (n= number passed in that function) Inside the while loop, do the addition of the numbers