Internet & World Wide Web How to Program, 5/e by Pearson Education, Inc. All Rights Reserved.

Similar documents
Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

JavaScript: Control Statements I Pearson Education, Inc. All rights reserved.

CS110D: PROGRAMMING LANGUAGE I

Chapter 3 Structured Program Development

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

JavaScript: Control Statements I

Unit 3. Operators. School of Science and Technology INTRODUCTION

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

Chapter 2: Functions and Control Structures

CSE123 LECTURE 3-1. Program Design and Control Structures Repetitions (Loops) 1-1

Control Statements. Musa M. Ameen Computer Engineering Dept.

Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition

Fundamentals of Programming. Lecture 6: Structured Development (part one)

CGS 3066: Spring 2015 JavaScript Reference

Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition

Structured Program Development in C

Programming - 1. Computer Science Department 011COMP-3 لغة البرمجة 1 لطالب كلية الحاسب اآللي ونظم المعلومات 011 عال- 3

In Fig. 3.5 and Fig. 3.7, we include some completely blank lines in the pseudocode for readability. programs into their various phases.

Working with JavaScript

Chapter 7. Additional Control Structures

CS313D: ADVANCED PROGRAMMING LANGUAGE

MEHMET YAYAN - İSMAİL HAKKI ÖZTÜRK CS101/SEC.-2 CLASS NOTES 1. March 28-30, 2007

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

CIS 3260 Intro to Programming in C#

Chapter 3 Structured Program Development in C Part II

Structured Program Development

Chapter 4: Control structures. Repetition

Chapter 2 Working with Data Types and Operators

Introduction to C/C++ Lecture 3 - Program Flow Control

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS

Chapter 3 - Simple JavaScript - Programming Basics. Lesson 1 - JavaScript: What is it and what does it look like?

Chapter 4: Control structures

COP 2000 Introduction to Computer Programming Mid-Term Exam Review

Fundamentals of Programming Session 7

Review of the C Programming Language for Principles of Operating Systems

Operators & Expressions

Operators in java Operator operands.

PLD Semester Exam Study Guide Dec. 2018

Operators in C. Staff Incharge: S.Sasirekha

Lecture 7 Tao Wang 1

Chapter 5 Control Statements: Part 2 Section 5.2 Essentials of Counter-Controlled Repetition

Introduction. C provides two styles of flow control:

Day05 A. Young W. Lim Sat. Young W. Lim Day05 A Sat 1 / 14

PHP: The Basics CISC 282. October 18, Approach Thus Far

Chapter 2 REXX STATEMENTS. SYS-ED/ Computer Education Techniques, Inc.

Full file at

More Programming Constructs -- Introduction

Operators. Lecture 12 Section Robb T. Koether. Hampden-Sydney College. Fri, Feb 9, 2018

Programming for Engineers Iteration

Operators. Java operators are classified into three categories:

Introduction to Bioinformatics

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

Flow Control. CSC215 Lecture

Introduction to C Programming

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

Review of the C Programming Language

Programming for the Web with PHP

Decision Making in C

Expressions & Assignment Statements

An Introduction to Programming with C++ Sixth Edition. Chapter 7 The Repetition Structure

Arithmetic Operators. Binary Arithmetic Operators. Arithmetic Operators. A Closer Look at the / Operator. A Closer Look at the % Operator

C++ Programming: From Problem Analysis to Program Design, Third Edition

Technical Questions. Q 1) What are the key features in C programming language?

Increment and the While. Class 15

Basics of Java Programming

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

Flow of Control. Flow of control The order in which statements are executed. Transfer of control

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed

The Arithmetic Operators

Information Science 1

A Look Back at Arithmetic Operators: the Increment and Decrement

Information Science 1

SECTION II: LANGUAGE BASICS

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

A flow chart is a graphical or symbolic representation of a process.

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Conditionals and Loops

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Fundamentals of Programming (Python) Control Structures. Sina Sajadmanesh Sharif University of Technology Fall 2017

Programming Fundamentals - A Modular Structured Approach using C++ By: Kenneth Leroy Busbee

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

3. Java - Language Constructs I

3 The L oop Control Structure

Data Types and Variables in C language

Chapter 7: Javascript: Control Statements. Background and Terminology. Background and Terminology. Background and Terminology

Information Science 1

Chapter 7. Expressions and Assignment Statements ISBN

Example. CS 201 Selection Structures (2) and Repetition. Nested if Statements with More Than One Variable

Chapter 4: Expressions. Chapter 4. Expressions. Copyright 2008 W. W. Norton & Company. All rights reserved.

1 Lexical Considerations

Repeating Instructions. C# Programming: From Problem Analysis to Program Design 2nd Edition. David McDonald, Ph.D. Director of Emerging Technologies

Chapter 3: Operators, Expressions and Type Conversion

Chapter 4: Control Structures I (Selection)

Overview of C, Part 2. CSE 130: Introduction to Programming in C Stony Brook University

Transcription:

Internet & World Wide Web How to Program, 5/e

Sequential execution Execute statements in the order they appear in the code Transfer of control Changing the order in which statements execute All scripts can be written in terms of only three control statements sequence selection repetition

JavaScript provides three selection structures. The if statement either performs (selects) an action if a condition is true or skips the action if the condition is false. Called a single-selection statement because it selects or ignores a single action or group of actions. The if else statement performs an action if a condition is true and performs a different action if the condition is false. Double-selection statement because it selects between two different actions or group of actions. The switch statement performs one of many different actions, depending on the value of an expression. Multiple-selection statement because it selects among many different actions or groups of actions.

JavaScript provides four repetition statements, namely, while, do while, for and for in. In addition to keywords, JavaScript has other words that are reserved for use by the language, such as the values null, true and false, and words that are reserved for possible future use.

Allows you to specify that different actions should be performed when the condition is true and when the condition is false.

Conditional operator (?:) Closely related to the if else statement JavaScript s only ternary operator it takes three operands The operands together with the?: operator form a conditional expression The first operand is a boolean expression The second is the value for the conditional expression if the boolean expression evaluates to true Third is the value for the conditional expression if the boolean expression evaluates to false

The following statement contains a conditional expression that evaluates to the string "Passed" if the condition studentgrade >= 60 is true and evaluates to the string "Failed" if the condition is false. document.writeln( studentgrade >= 60? "Passed" : "Failed" );

Nested if else statements Test for multiple cases by placing if else statements inside other if else statements The JavaScript interpreter always associates an else with the previous if, unless told to do otherwise by the placement of braces ({}) The if selection statement expects only one statement in its body To include several statements, enclose the statements in braces ({ and }) A set of statements contained within a pair of braces is called a block

It s important to note that the JavaScript interpreter always associates an else with the previous if, unless told to do otherwise by the placement of braces ({}).

This statement tests whether x is greater than 5. If so, execution continues by testing whether y is also greater than 5. If the second condition is true, the proper string "x and y are > 5" is displayed. However, if the second condition is false, the string "x is <= 5" is displayed, even though we know that x is greater than 5.

To force the first nested if statement to execute as it was intended originally, we must write it as follows: The braces ({}) indicate to the JavaScript interpreter that the second if statement is in the body of the first if statement and that the else is matched with the first if statement.

A logic error has its effect at execution time. A fatal logic error causes a script to fail and terminate prematurely. A nonfatal logic error allows a script to continue executing, but the script produces incorrect results.

while Allows you to specify that an action is to be repeated while some condition remains true The body of a loop may be a single statement or a block Eventually, the condition becomes false and repetition terminates

JavaScript represents all numbers as floatingpoint numbers in memory Floating-point numbers often develop through division The computer allocates only a fixed amount of space to hold such a value, so the stored floating-point value can only be an approximation

Sentinel-controlled repetition Special value called a sentinel value (also called a signal value, a dummy value or a flag value) indicates the end of data entry Often is called indefinite repetition, because the number of repetitions is not known in advance Choose a sentinel value that cannot be confused with an acceptable input value

Control structures may be nested inside of one another

JavaScript provides the arithmetic assignment operators +=, -=, *=, /= and %=, which abbreviate certain common types of expressions.

The increment operator, ++, and the decrement operator, --, increment or decrement a variable by 1, respectively. If the operator is prefixed to the variable, the variable is incremented or decremented by 1, then used in its expression. If the operator is postfixed to the variable, the variable is used in its expression, then incremented or decremented by 1.