IST 210: PHP Logic IST 210: Organization of Data IST2101.

Slides:



Advertisements
Similar presentations
Chapter 4: Control Structures I (Selection)
Advertisements

CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
How SAS implements structured programming constructs
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
If Statements Sections 1.25, Control Structures o All code thus far executes every line of code sequentially o We want to be able to repeat,
Flow of Control. 2 Control Structures Control structure: An instruction that determines the order in which other instructions in a program are executed.
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
Programming in Java Unit 4. Learning outcome:  LO2: Be able to design Java solutions  LO3: Be able to implement Java solutions Assessment criteria:
PHP Logic. Review: Variables Variables: a symbol or name that stands for a value – Data types ( Similar to C++ or Java): Int, Float, Boolean, String,
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
Algorithm Design.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
Python Mini-Course University of Oklahoma Department of Psychology Day 2 – Lesson 7 Conditionals and Loops 4/18/09 Python Mini-Course: Day 2 - Lesson 7.
Repetition. Control of Flow SEQUENCE SELECTION (if..else, switch…case) REPETITION.
Exercise 1: IF/ELSE Step 1: Open NotePad++ and create “number.php” in your webspace Step 2: Write codes to do the following 1.Generate a random number.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
ITEC 109 Lecture 11 While loops. while loops Review Choices –1 st –2 nd to ?th –Last What happens if you only use ifs? Can you have just an else by itself?
CSCI 161 Lecture 7 Martin van Bommel. Control Statements Statements that affect the sequence of execution of other statements Normal is sequential May.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
While and If-Else Loops ROBOTC Software. While Loops While loop is a structure within ROBOTC Allows a section of code to be repeated as long as a certain.
Structured Programming The Basics. Control structures They control the order of execution What order statements will be done in, or whether they will.
CST336, Dr. Krzysztof Pietroszek Week 2: PHP. 1.Introduction to PHP 2.Embed PHP code into an HTML web page 3.Generate (output HTML) web page using PHP.
8. DECISION STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
Controlling Computers with Programs When you create a computer program you are creating a set of instructions that tell the computer exactly and completely.
Programming Language C++ Lecture 3. Control Structures  C++ provides control structures that serve to specify what has to be done to perform our program.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
USING CONDITIONAL CODE AMIR KHANZADA. Conditional Statement  Conditional statements are the set of commands used to perform different actions based on.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Variables, operators, canvas, and multimedia Dr. Reyes.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Control Structures (Selection & Repetition)
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Programming Logic and Design Fourth Edition, Introductory Chapter 2 Understanding Structure.
if ( condition ) statement; if is a Java reserved word The condition must be a boolean expression. It must evaluate to either true or false.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. 4 Simple Flow of Control.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
Structured Programming The Basics
FOP: While Loops.
Sequence, Selection, Iteration The IF Statement
CiS 260: App Dev I Chapter 4: Control Structures II.
Expressions and Control Flow in JavaScript
JavaScript: Control Statements.
JavaScript: Control Statements I
Control Structures – Selection
Software Programming J. Holvikivi 2014.
Iteration with While You can say that again.
While Loops and If-Else Structures
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
Coding Concepts (Basics)
3 Control Statements:.
Java Programming Control Structures Part 1
Design and Implementation
Pages:51-59 Section: Control1 : decisions
Three Special Structures – Case, Do While, and Do Until
Summary Two basic concepts: variables and assignments Basic types:
Computer Science Core Concepts
ICT Programming Lesson 3:
if-else Structures Principles of Engineering
Flow of Control.
Relational Operators.
FLUENCY WITH INFORMATION TECNOLOGY
PROGRAM FLOWCHART Iteration Statements.
Javascript Chapter 19 and 20 5/3/2019.
Pages:51-59 Section: Control1 : decisions
Presentation transcript:

IST 210: PHP Logic IST 210: Organization of Data IST2101

PHP Basics Logical Structures –Sequence –Selection –Loop 2IST210

Statements Statement: an instruction written in a high-level language –Assignment statement $filename=“abc.txt”; $x = 5+3; $y = (5 == 3); –Input/output statement echo “test”; 3IST210

Logic Structures Three basic logic structures –Sequence –Selection –Loop 4IST210

Sequence The program, when run, must perform each action in order with no possibility of skipping an action or branching off to another action. Sequence: Statement 1 Statement 2 Statement 3 …… 5IST210

Sequence To display headings 6IST210 <?php echo " Heading 1 "; echo " Heading 2 "; echo " Heading 3 "; echo " Heading 4 "; echo " Heading 5 "; echo " Heading 6 "; ?>

Selection/Decision In a selection structure, a question is asked, and depending on the answer, the program takes one of two courses of action, after which the program moves on to the next event. Selection if expression then statement 1 else statement 2 7IST210

IF/ELSE if – else if (Expression) Statement if (Expression) Statement 1 else Statement 2 IST2108 <?php $x = 20; if ($x >100) echo "x is a large number."; else echo "x is a small number."; ?> Try it

IF/ELSE More than one statement: Use braces {} IST2109 <?php $x = 200; if ($x >100) { echo "x is a large number. "; echo "x is greater than 100"; } else { echo "x is a small number. "; echo "x is smaller than 100"; } ?> Try it

IF/ELSE: Exercise IST21010 <?php $x = 200; $y = 100; if ($x = $y) { echo "x equals to y"; } else { echo "x does not equal to y"; } ?> Debug $x does not equal to y. Where is the bug?

A Very Common Mistake A==B: boolean value, true (1) or false (0) A=B: assign variable B’s value to variable A. (The value of the assignment operation is 1.) if (x = 1)  This is always true! then …

Loop A structure to repeat an action multiple times under a given condition. Loops constitute one of the most basic and powerful programming concepts. 12IST210

Loop Three approaches to do loops 1.while (Expression) Statement; 2.for (Expression1; Expression2; Expression3) Statement; IST21013 <?php $i=1; while ($i<=6) { echo " Heading $i "; $i++; } ?> <? php for ($i=1; $i<=6; $i++) echo " Heading $i "; ?> Try it

For Loop for (Expression1; Expression2; Expression3) Statement; Expression1: Initialization expression –executed exactly once -- before the first evaluation of the test expression Expression2: Test expression –evaluated each time before the code in the for loop executes Expression3: Increment expression –executed after each iteration of the loop, often used to increment the loop variable, which is initialized in the initialization expression and tested in the test expression. for ($i=1; $i<=6; $i++) echo " Heading $i "; IST21014

Loop A very common mistake in Loop: infinite loop –Case 1: –Case 2: IST21015 for ($i=1; $i<=6; $i++) { echo " Heading $i "; $i = 1; } $i=1; while ($i<=6) { echo " Heading $i "; }

Combinations of Logic Structure A PHP file usually combines different control structures. 16IST210