Study guide

9.1 Procedures, Parameters, Return Values, Nested Calls, and Scope

Praxis Computer Science 5652

Track your progress as you read

Finished sections get a check mark.

1 Chapter 1: Praxis 5652 Exam Overview and ETS Pseudocode

1.1 Praxis 5652 Test Facts, Scoring, and Registration 1.2 Official ETS Pseudocode Notation and Tracing Strategy

2 Chapter 2: Impacts of Computing: Innovation, Access, and Effects

2.1 Computing for Creativity, Problem Solving, Communication, and Innovation 2.2 Equal Access, the Digital Divide, and Accessibility 2.3 Beneficial and Harmful Effects of Computing Innovations

3 Chapter 3: Impacts of Computing: Intellectual Property, Ethics, Privacy, and Security

3.1 Intellectual Property: Copyright, Open Source, and Creative Commons 3.2 Ethical and Unethical Computing Practices and Their Implications 3.3 Privacy, Security, Data Collection, and Local vs. Cloud Storage

4 Chapter 4: Algorithms and Computational Thinking: Abstraction, Decomposition, Number Bases, and Representation

4.1 Abstraction and Abstraction Hierarchies 4.2 Decomposition, Pattern Recognition, and Developing Algorithms 4.3 Number Bases: Binary, Octal, Decimal, and Hexadecimal 4.4 Algorithm Formats: Natural Language, Flowcharts, Pseudocode, and Tracing

5 Chapter 5: Algorithms: Efficiency, Limits of Computing, and Randomization

5.1 Algorithm Efficiency: Linear, Quadratic, Exponential, and Logarithmic Growth 5.2 Limits of Computing: Unsolvable Problems, Intractability, and Heuristics 5.3 Randomization, Random vs. Pseudorandom Numbers, and Scaling to a Range

6 Chapter 6: Algorithms: Searching, Sorting, and Recursion

6.1 Searching Algorithms: Linear Search and Binary Search 6.2 Sorting Algorithms: Tracing, Comparisons, Correctness, and Efficiency 6.3 Recursion: Base Cases, Tracing, Errors, and Iterative Equivalents

7 Chapter 7: Programming: Variables, Data Types, Strings, and Expressions

7.1 Variables, Data Types, and Type Conversion 7.2 Strings and String Operations 7.3 Operators, Precedence, Expressions, and Formulas 7.4 Boolean Expressions, Truth Tables, and Boolean Algebra

8 Chapter 8: Programming: Selection, Iteration, and Writing Code

8.1 Sequence and Selection: if, else, Chained and Nested Conditions 8.2 Iteration: for, while, do … while, and repeat … until Loops 8.3 Reading, Completing, and Modifying Code

9 Chapter 9: Programming: Procedures, Arrays, and Data Structures

9.1 Procedures, Parameters, Return Values, Nested Calls, and Scope 9.2 Arrays, Lists, and Two-Dimensional Arrays 9.3 Stacks, Queues, and Dictionaries (Maps)

10 Chapter 10: Programming: Correctness, Errors, Testing, and Code Quality

10.1 Program Correctness: Preconditions, Postconditions, Invariants, and Testing vs. Proof 10.2 Error Types and Debugging Techniques 10.3 Choosing Useful Test Cases: Boundaries, Partitions, Coverage, and Regression 10.4 Extensibility, Modifiability, and Reusability: Constants and Parameterization 10.5 Documentation, Code Reviews, Peer Feedback, and End-User Feedback

11 Chapter 11: Programming: Events, Usability, Input Validation, and APIs

11.1 Event-Driven Programming, Asynchronous Events, and Concurrency 11.2 Usability, Meaningful Error Messages, and Input Validation vs. Verification 11.3 Libraries and APIs: Reading Definitions, Making Calls, and Weighing Trade-offs

12 Chapter 12: Programming: Languages, Tools, Paradigms, and Object-Oriented Design

12.1 Low- and High-Level Languages, Compilers and Interpreters, and IDEs 12.2 Programming Paradigms: Procedural, Object-Oriented, and Others 12.3 Classes, Objects, Instance Variables, Methods, and Encapsulation 12.4 Inheritance, Polymorphism, and Overloading vs. Overriding

13 Chapter 13: Data: Bits, Encoding, Compression, and Encryption

13.1 Bits and Bytes: Why Binary, Storage Calculations, and Signed Integers 13.2 Encoding Text, Images, and Sound 13.3 Lossless and Lossy Compression: Run-Length Encoding, Huffman Coding, and Media Formats 13.4 Encoding vs. Encryption, Symmetric and Public-Key Encryption, and Their Trade-offs

14 Chapter 14: Data: Analysis Tools, Simulation, Storage, and Collection

14.1 Analyzing Data with Spreadsheets: Cleaning, Transforming, and Visualizing 14.2 Simulation and Modeling 14.3 Files, Databases, and Storage Requirements: Scale, Redundancy, and Backup 14.4 Collecting, Aggregating, and Generating Data: Public Data Sets, Surveys, Sensors, and Crowdsourcing

15 Chapter 15: Computing Systems: Hardware, Operating Systems, and Computing Environments

15.1 Hardware Components and the Fetch–Decode–Execute Cycle 15.2 Operating Systems, Software Components, and Resource Issues 15.3 Embedded Systems, the Internet of Things, and Types of Computing Systems 15.4 Local, Network, and Cloud Computing and Storage; How Binary Data Are Stored

16 Chapter 16: Networks, the Internet, the Web, and Cybersecurity

16.1 Network Types and Wired and Wireless Communication 16.2 Network Hardware and Layered Network Models (OSI and TCP/IP) 16.3 Network Performance: Bandwidth, Latency, Load, and Estimating Needs 16.4 How the Internet Works: Protocols, IP Addressing, DNS, URLs, and Reliability 16.5 The Web: HTTP, HTML and Markup Languages, Browsers, Servers, and Clients 16.6 Cybersecurity: The Five Pillars, Strong Passwords, Security Strategies, and Trade-offs

9.1 Procedures, Parameters, Return Values, Nested Calls, and Scope

Key Takeaways Explain This Topic AI

A procedure header such as int newScore ( int a, int b, int old ) gives the return type, the name, and the typed parameters; void means nothing is returned.

Arguments are matched to parameters by position, and a return statement ends the procedure immediately and sends a value back to the caller.

In nested calls such as twice ( plusThree ( 4 ) ), the innermost call runs first and its result becomes the argument of the outer call.

Assigning a new value to a primitive parameter inside a procedure does not change the caller's variable, but changing an element of an array parameter changes the caller's array.

A local variable exists only inside its procedure or block; a local variable with the same name as a global variable shadows it without changing it.

Last updated: September 2026

What this competency asks

ETS asks you to understand how to write and call procedures with parameters and return values . Besides tracing, finding missing code, and identifying equivalent code, two skills are specific to procedures:

Trace code when references to objects and arrays are passed to procedures.

Trace code that includes nested procedure calls.

The data-types competency adds: distinguish between global and local scope .

Why procedures matter

A procedure (also called a function, method, or subroutine) packages a task behind a name. This gives you procedural abstraction : callers need to know what the procedure does, not how. Procedures avoid duplicated code, let a large program be built and tested in pieces, and make changes safer, because a fix in one place applies everywhere the procedure is called. ETS's sample dice-game question hinges on choosing the correct body for a procedure newScore ( dieOne, dieTwo, score ) whose purpose is described only by a table of results.

  • Procedure syntax in ETS pseudocode int area ( int width, int height ) // returns an int
  • return width * height
  • end area
  • void printBanner ( String title ) // returns nothing
  • print "*** " + title + " ***"
  • end printBanner
  • Term Meaning Example
  • Parameter (formal parameter) A variable named in the header width , height
  • Argument (actual parameter) The value supplied in the call area ( 3, 4 ) : 3 and 4
  • Return type Type of the value sent back int , or void for none
  • Return value The value produced by return 12

Arguments match parameters by position : the first argument goes to the first parameter, and so on. A return statement ends the procedure at once . Statements after it in the same path never run.

A value-returning procedure is used inside an expression: int a ← area ( 3, 4 ) + 1 . A void procedure is called as a statement on its own: printBanner ( "Welcome" ) .

Tracing a call

For each call:

Evaluate the arguments.

Create fresh parameter variables and copy the argument values into them.

Run the body, tracking local variables.

  • At return , send the value back to the exact place the call appeared. int addBonus ( int score )
  • score ← score + 5
  • return score
  • end addBonus
  • int s ← 80
  • int t ← addBonus ( s )
  • print s + " " + t

The parameter score starts as a copy of s (80) and becomes 85, which is returned into t. The caller's s is unchanged, so the output is 80 85 .

  • Nested calls
  • When a call appears as an argument, evaluate from the inside out : int twice ( int x )
  • return 2 * x
  • end twice
  • int plusThree ( int x )
  • return x + 3
  • end plusThree

print twice ( plusThree ( 4 ) ) + plusThree ( twice ( 4 ) )

plusThree ( 4 ) = 7, so twice ( 7 ) = 14.

twice ( 4 ) = 8, so plusThree ( 8 ) = 11.

The output is 14 + 11 = 25 . The order of composition matters.

Procedures can also call other procedures from inside their bodies. Keep a stack of "who is waiting for whom". Each caller pauses until its callee returns, exactly as in recursion (Section 6.3).

Passing arrays and objects

A variable of a primitive type ( int , double , boolean , char ) holds its value directly. A variable that refers to an array or object holds a reference to it. When you pass it, the procedure receives a copy of the reference , so both names refer to the same array. void update ( int[ ] arr, int x )

  • arr[0] ← arr[0] + 10 // changes the caller's array
  • x ← x + 10 // changes only the local copy
  • end update
  • int[ ] nums ← {1, 2, 3}
  • int y ← 5
  • update ( nums, y )
  • print nums[0] + " " + y

The output is 11 5 . The array element changed because arr and nums refer to the same array. y did not change because x was a separate copy.

A subtler case, following the Java model: if a procedure assigns a whole new array to its parameter ( arr ← new array ), only the local reference changes, and the caller still refers to the original array. ETS's sample sort question relies on this sharing: a helper call swap ( arr, i, j ) exchanges two elements of the caller's array.

Some languages, such as C++ with & parameters, also offer pass-by-reference for primitive variables, which lets the procedure change the caller's variable directly. Unless a question says so, assume primitives are copied.

Scope and lifetime

Scope is the region of code where a name can be used. Lifetime is how long the variable exists while the program runs.

  • Kind Declared Visible Exists
  • Local Inside a procedure or block (including loop headers) Only there While that procedure call or block runs
  • Parameter In the procedure header Only inside the procedure For one call
  • Global Outside all procedures Everywhere, unless shadowed For the whole program

Shadowing: a local variable with the same name as a global variable hides the global inside that procedure. int count ← 100 // global

  • int process ( )
  • int count ← 10 // local; shadows the global
  • for ( int k ← 1; k ≤ 3; k ← k + 1 )
  • count ← count + k
  • end for
  • return count
  • end process
  • int result ← process ( )
  • print count + " " + result

The local count becomes 10 + 1 + 2 + 3 = 16 and is returned. The global count is untouched. Output: 100 16 . The declaration int count inside the procedure is what creates the new local variable. Without it, the procedure would be updating the global.

Why avoid globals? Any procedure can change a global variable, which creates hidden dependencies. A bug in one place can corrupt a value used somewhere else, and procedures become hard to test on their own. Passing values in as parameters and returning results keeps each procedure self-contained.