Chapter 2: Functions and Control Structures

Similar documents
1/22/2017. Chapter 2. Functions and Control Structures. Calling Functions. Objectives. Defining Functions (continued) Defining Functions

Introduction. C provides two styles of flow control:

Loops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017

LECTURE 5 Control Structures Part 2

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

C++ Programming Lecture 7 Control Structure I (Repetition) Part I

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

Theory of control structures

V3 1/3/2015. Programming in C. Example 1. Example Ch 05 A 1. What if we want to process three different pairs of integers?

REPETITION CONTROL STRUCTURE LOGO

Second Term ( ) Department of Computer Science Foundation Year Program Umm Al Qura University, Makkah

What is PHP? [1] Figure 1 [1]

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

First Name: Last: ID# 1. Hexadecimal uses the symbols 1, 2, 3, 4, 5, 6, 7 8, 9, A, B, C, D, E, F,G.

Programming Basics and Practice GEDB029 Decision Making, Branching and Looping. Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029

In this chapter you will learn:

All copyrights reserved - KV NAD, Aluva. Dinesh Kumar Ram PGT(CS) KV NAD Aluva

8. Control statements

Flow Control. CSC215 Lecture

Repetition Structures

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

LESSON 3. In this lesson you will learn about the conditional and looping constructs that allow you to control the flow of a PHP script.

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

COMP519 Web Programming Lecture 27: PHP (Part 3) Handouts

Object-Oriented Programming in Java

M275 - Web Development using PHP and MySQL

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

3 The L oop Control Structure

Lecture 5 Tao Wang 1

Fundamentals of Programming Session 13

Unit 2: Java in the small. Prepared by: Dr. Abdallah Mohamed, AOU-KW

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6)

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

Loops and Files. Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Unit 2: Java in the small

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

Information Science 1


YOLOP Language Reference Manual

Chapter 5: Control Structures II (Repetition) Objectives (cont d.) Objectives. while Looping (Repetition) Structure. Why Is Repetition Needed?

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

XQ: An XML Query Language Language Reference Manual

Control Structures. CIS 118 Intro to LINUX

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

For Loop. Variations on Format & Specific Examples

Decision Making in C

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

Introduction to Java & Fundamental Data Types

SSOL Language Reference Manual

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

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

CGS 3066: Spring 2015 JavaScript Reference

COMP284 Scripting Languages Lecture 11: PHP (Part 3) Handouts

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 5: Control Structures II (Repetition)

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.

Iterative Languages. Scoping

Quiz 1: Functions and Procedures

Chapter 4: Loops and Files

Unit 3 Decision making, Looping and Arrays

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.

Java Bytecode (binary file)

204111: Computer and Programming

1 Lexical Considerations

Chapter 8 Statement-Level Control Structures

Information Science 1

egrapher Language Reference Manual

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. Looping. ++ is the increment operator.

L o o p s. for(initializing expression; control expression; step expression) { one or more statements }

C-LANGUAGE CURRICULAM

Structure of Programming Languages Lecture 5

CSI33 Data Structures

Why Is Repetition Needed?

Lab 5 - Repetition. September 26, 2018

GNU ccscript Scripting Guide IV

Starting Out with C++: Early Objects, 9 th ed. (Gaddis, Walters & Muganda) Chapter 2 Introduction to C++ Chapter 2 Test 1 Key

STUDENT LESSON A12 Iterations

Problem Solving With Loops

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

Add Subtract Multiply Divide

Module 4: Decision-making and forming loops

COSC 123 Computer Creativity. Java Decisions and Loops. Dr. Ramon Lawrence University of British Columbia Okanagan

Lexical Considerations

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Control Statements. Musa M. Ameen Computer Engineering Dept.

Control Structures. Code can be purely arithmetic assignments. At some point we will need some kind of control or decision making process to occur

Chapter 4: Loops and Files

Review of the C Programming Language for Principles of Operating Systems

CSC Web Programming. Introduction to JavaScript

The following expression causes a divide by zero error:

Boolean evaluation and if statements. Making decisions in programs

PHPoC Language Reference > Overview. Overview

Java+- Language Reference Manual

Chapter 4 Introduction to Control Statements

CHAD Language Reference Manual

CSCE 206: Structured Programming in C++

VENTURE. Section 1. Lexical Elements. 1.1 Identifiers. 1.2 Keywords. 1.3 Literals

In this lab, you will learn more about selection statements. You will get familiar to

Chapter 3. More Flow of Control. Copyright 2008 Pearson Addison-Wesley. All rights reserved.

Transcription:

Chapter 2: Functions and Control Structures TRUE/FALSE 1. A function definition contains the lines of code that make up a function. T PTS: 1 REF: 75 2. Functions are placed within parentheses that follow a parameter name. F PTS: 1 REF: 75 3. A function must contain a parameter. F PTS: 1 REF: 76 4. Function arguments are the statements that do the actual work of the function and must be contained within the function braces. F PTS: 1 REF: 76 5. A function executes automatically. F PTS: 1 REF: 77 6. Like variables, function names are case sensitive. F PTS: 1 REF: 78 7. A return statement is a statement that returns a value to the statement that called the function. T PTS: 1 REF: 78 8. A function must return a value. F PTS: 1 REF: 78 9. Variable scope refers to the location that a declared variable can be used. T PTS: 1 REF: 82 10. If you attempt to use a local variable outside the function in which it is declared, you receive an error message. T PTS: 1 REF: 82 11. The formal parameters within the parentheses of a function declaration are global variables. F PTS: 1 REF: 82 12. Global variables are automatically available to all parts of your program, including functions.

F PTS: 1 REF: 82 13. In PHP, you must declare a global variable with the global keyword inside a function definition for the variable to be available within the scope of that function. T PTS: 1 REF: 82-83 14. Using parentheses to enclose the conditional expression of an if statement is optional. F PTS: 1 REF: 84 15. If a command block is missing either the opening or closing brace, an error occurs. T PTS: 1 REF: 84 16. The else clause can only be used with an if statement. T PTS: 1 REF: 88 17. When one decision-making statement is contained within another decision-making statement, they are referred to as multiple decision-making structures. F PTS: 1 REF: 89 18. The switch statement controls program flow by executing a specific set of statements, depending on the value of an expression. T PTS: 1 REF: 92 19. The default label contains statements that execute when the value returned by the switch statement expression does not match any case label. T PTS: 1 REF: 93 20. To ensure that the while statement will eventually end, you must include code within the body of the while statement that changes the value of the conditional expression. T PTS: 1 REF: 99 21. You can use the terminate statement to halt a looping statement and restart the loop with a new iteration. F PTS: 1 REF: 99 22. The do...while statement executes a statement or statements once, then repeats the execution as long as a given conditional expression evaluates to TRUE. T PTS: 1 REF: 100 23. The statements in a do...while statement always execute repeatedly before the conditional expression evaluates the count variable.

F PTS: 1 REF: 101 24. The for statement performs essentially the same function as the while statement. T PTS: 1 REF: 103 25. One of the primary differences between the while statement and the for statement is that in addition to a conditional expression, the for statement can also include code that initializes a counter and changes its value with each iteration. T PTS: 1 REF: 103 26. The for...while statement is used to iterate or loop through the elements in an array. F PTS: 1 REF: 105 27. You will not receive an error if you attempt to use a foreach statement with any variable types other than arrays. F PTS: 1 REF: 106 28. The primary use of the include and require statements is to reuse content on multiple web pages by allowing you to insert the content of an external file, called an include file, in your PHP scripts. T PTS: 1 REF: 109-110 29. The include statement and the require statement perform the same function and can be used interchangeably. F PTS: 1 REF: 110 30. Include statements support only absolute path notation. F PTS: 1 REF: 111 MULTIPLE CHOICE 1. When you use a variable in a PHP program, you must be aware of the variable s. a. placement c. function b. scope d. statement B PTS: 1 REF: 82 2. A variable s scope can be either global or. a. local c. universal b. undeclared d. declared A PTS: 1 REF: 82 3. What will be returned if you use a local variable outside the function in which it is declared? a. value c. function b. error message d. nothing

B PTS: 1 REF: 82 4. The parameters within the parentheses of a function declaration are what kind of variables? a. local c. unknown b. global d. declared A PTS: 1 REF: 82 5. With many programming languages, global variables are automatically available to all parts of your program, including. a. statements c. functions b. definitions d. declarations C PTS: 1 REF: 82 6. When you declare a global variable with the global keyword, you do not need to assign the variable a(n). a. value c. function b. definition d. name A PTS: 1 REF: 83 7. A command block is a group of statements within a set of opening and closing. a. brackets c. parentheses b. braces d. quotation marks B PTS: 1 REF: 84 8. When one decision-making statement is contained within another decision-making statement it is referred to as a decision-making structure. a. enclosed c. nested b. contained d. layered C PTS: 1 REF: 89 9. Which of the following terms is not associated with the switch statement? a. switch title c. executable statements b. case label d. break keyword A PTS: 1 REF: 92 10. A(n) statement is a control structure that repeatedly executes a statement or series of statements while a specific condition is TRUE or until a specific condition becomes TRUE. a. repeat c. loop b. replicate d. circular C 11. A is a variable that increments or decrements with each iteration of a loop statement a. counter c. iterator b. incrementer/decrementer d. repetitor A 12. If you do not include code that changes the value used the by the condition expression, your program will be caught in a loop.

a. continuous c. constant b. continuing d. infinite D PTS: 1 REF: 99 13. A statement is used to iterate or loop through the elements in an array. a. for c. foreach b. while d. if...else C PTS: 1 REF: 105 14. The statement halts the processing of the web page and displays an error if an include file cannot be found. a. include c. Insert-contents b. insert d. require D PTS: 1 REF: 110 15. The file is typically saved with a prefix of inc_. a. insert c. nested b. include d. increment B PTS: 1 REF: 110 COMPLETION 1. Groups of statements you can execute as a single unit are called. functions PTS: 1 REF: 75 2. -control statements allow you to determine the order in which statements execute in a program. Flow PTS: 1 REF: 83 3. The function is the lines of code that make up a function definition PTS: 1 REF: 75 4. A formal is a variable that is used within a function. parameter PTS: 1 REF: 75 5. A function executes a function call

PTS: 1 REF: 77 6. A statement is a statement that returns a value to the statement that called the function. return PTS: 1 REF: 78 7. Passing by means that the actual variable is used within the function and any changes made to the variable by the function will remain after the function completes. reference PTS: 1 REF: 80 8. A variable is declared outside a function and is available to all parts of the program. global PTS: 1 REF: 82 9. A variable is declared inside a function and is only available within the function in which it is declared. local PTS: 1 REF: 82 10. You must use the keyword to declare a global variable within the scope of a function. global PTS: 1 REF: 82-83 11. The statement is used to execute specific programming code if the evaluation of a conditional expression returns a value of true. if PTS: 1 REF: 84 12. A(n) block is a group of statements contained within a set of braces, similar to the way function statements are contained within a set of braces command PTS: 1 REF: 84 13. An if statement that includes an else clause is called a(n) statement.

if...else ifelse if else PTS: 1 REF: 88 14. When one decision-making statement is contained within another decision-making statement, they are called decision-making structures. nested PTS: 1 REF: 89 15. are added to both the if and else portions of the if...else statement if a section contains more than one statement. Braces PTS: 1 REF: 90 16. The statement controls program flow using a case statement that executing a specific set of statements, depending on the value of an expression. switch PTS: 1 REF: 92 17. The switch statement compares the value of an expression to a value contained within a special statement called a. case label PTS: 1 REF: 92 18. A switch statement contains the following components: the keyword switch, an expression, an opening brace, a case label, the executable statements, the keyword, a default label, and a closing brace. break PTS: 1 REF: 92 19. case $ExampleVar is an example of a data type being used as a case label variable name variable PTS: 1 REF: 93

20. case "Monday" is an example of a data type being used as a case label. string literal string literal PTS: 1 REF: 93 21. case 42 is an example of a data type being used as a case label. integer literal integer PTS: 1 REF: 93 22. case 125.78 is an example of a data type being used as a case label. floating-point literal floating point floating-point PTS: 1 REF: 93 23. The label contains statements that execute when the value returned by the switch statement expression does not match a case label. default PTS: 1 REF: 93 24. The final statement after the final case or default statement is not required. break PTS: 1 REF: 94 25. A(n) statement is a control structure that repeatedly executes a statement or a series of statements while a specific condition is TRUE or until a specific condition becomes TRUE. loop 26. The statement repeats a statement or series of statements as long as a given conditional expression evaluates to TRUE. while

27. The conditional expression in the while statement is enclosed within following the keyword while. parentheses () 28. Each repetition of a looping statement is called a(n). iteration 29. A statement keeps repeating until its conditional expression evaluates to FALSE. while 30. A is a variable that increments or decrements with each iteration of a loop statement. counter 31. In a(n) loop, a loop statement never ends because its conditional expression is never FALSE. infinite PTS: 1 REF: 99 32. The loop executes a statement or statements once, then repeats the execution as long as a given conditional expression evaluates to TRUE. do...while do while PTS: 1 REF: 100 33. The statement is used for repeating a statement or series of statements as long as a given conditional expression evaluates to TRUE. for PTS: 1 REF: 103

34. You must include a(n) to separate each section in a for loop. semicolon ; PTS: 1 REF: 104 35. The statement is used to iterate or loop through the elements in an array. foreach PTS: 1 REF: 105 36. In a foreach statement, you use the $variable_name to access the value of the element that is available in an iteration. argument PTS: 1 REF: 106 37. The statement generates a warning if the include file cannot be found. include PTS: 1 REF: 110 38. With the statement the program assure that the file is added to the script only once and halts the processing of the web page and displays an error message if the include file cannot be found. require_once PTS: 1 REF: 110