ASVAB Practice

Basic Programming and Logic

You will not be asked to write code, but you will be asked to read it and predict what it does.

Building blocks

  • Variable — a named storage location holding a value. Types: integer, float, string, boolean.
  • Constant — a value that does not change.
  • Operator — arithmetic (+ - * /), comparison (== != < >), logical (AND OR NOT).
  • Function — a named block of code that takes inputs and returns output.

Control flow

  • Sequence — top to bottom.
  • Selectionif / else if / else branches based on a condition.
  • Iterationfor loops a known number of times; while loops until a condition becomes false.
  • Infinite loop — exit condition is never reached. The program hangs.

Boolean logic and truth tables

A B A AND B A OR B NOT A A XOR B
T T T T F F
T F F T F T
F T F T T T
F F F F T F

AND is true only when both inputs are true. OR is true when either is true. NOT flips. XOR (exclusive or) is true when exactly one input is true.

Number bases

  • Binary (base 2) — digits 0, 1. The native language of digital electronics.
  • Decimal (base 10) — digits 0–9. Human default.
  • Hexadecimal (base 16) — digits 0–9, A–F. Each hex digit = 4 bits. Used for memory addresses, MAC addresses, colors (#FF0000 = red).

Quick conversions to memorize:

Binary Decimal Hex
0000 0 0
0001 1 1
1000 8 8
1001 9 9
1010 10 A
1111 15 F
1111 1111 255 FF

Reading pseudocode

Pseudocode is plain-English code that captures logic without committing to a language. Walk it line by line; track variable values on scratch paper.

SET x = 5
SET y = 2
WHILE y < x
    SET y = y + 1
    PRINT y
END WHILE

Trace: y starts at 2. Loop checks y < 5. - Iter 1: y = 3, print 3. - Iter 2: y = 4, print 4. - Iter 3: y = 5, print 5. Now y < x is false. Loop exits.

Output: 3 4 5.

Algorithms

An algorithm is a step-by-step procedure for solving a problem. You may see one item asking what a short algorithm does — read it the same way as pseudocode and trace the output.

Debugging

Read the error message, reproduce the bug, narrow down the line that fails, fix it, retest.

Other concepts in Cyber