LEARN · COLDFUSION · PRACTICE
50 CFML Logic Questions
Five levels, basic conditionals to real-world application design. Pick a question, write your CFML, and run it in a free online playground, no account on this site required.
Open a CFML Playground
Write and run your solutions on real Adobe ColdFusion, free, with no signup required.
Open CFFiddle ↗Opens a third-party CFML playground in a new tab. External site terms and privacy policy apply. Prefer multi-engine setups like Lucee or BoxLang? Try TryCF instead.
Level 1 · Basic Logic
Q1–10Variables, conditions, loops, and basic calculations.
Even or Odd
Write a CFML program to check whether a given number is even or odd.
Positive, Negative, or Zero
Determine whether a number is positive, negative, or zero.
Largest of Two Numbers
Find the largest of two numbers without using a built-in maximum function.
Largest of Three Numbers
Find the largest of three numbers using conditional statements.
Swap Two Variables
Swap two variable values with and without using a temporary variable.
Sum of Natural Numbers
Calculate the sum of numbers from 1 to N using a loop.
Multiplication Table
Print the multiplication table of a given number from 1 to 10.
Factorial
Calculate the factorial of a number using a loop.
Leap Year
Check whether a given year is a leap year.
Divisibility Check
Check whether a number is divisible by both 3 and 5.
Level 2 · Number-Based Logic
Q11–20Mathematical operations, number properties, and algorithms.
Reverse a Number
Reverse the digits of a number. Example: 1234 → 4321.
Palindrome Number
Check whether a number reads the same forward and backward. Example: 121.
Prime Number
Determine whether a number is prime.
Prime Numbers in a Range
Print all prime numbers between 1 and 100.
Fibonacci Series
Generate the first N terms of the Fibonacci sequence.
Sum of Digits
Calculate the sum of the digits of a number. Example: 1234 → 10.
Count Digits
Count the number of digits in an integer.
Armstrong Number
Check whether a number is an Armstrong number. Example: 153 = 1³ + 5³ + 3³.
GCD and LCM
Calculate the greatest common divisor and least common multiple of two numbers.
Perfect Number
Check whether a number equals the sum of its positive divisors excluding itself. Example: 28.
Level 3 · Strings and Arrays
Q21–30String functions, arrays, loops, and data manipulation.
Reverse a String
Reverse a string without using a built-in reverse function.
Palindrome String
Check whether a string is a palindrome, ignoring letter case.
Count Vowels and Consonants
Count vowels and consonants in a given string.
Character Frequency
Count how many times each character appears in a string.
Remove Duplicate Characters
Remove repeated characters from a string while preserving order.
Anagram Check
Check whether two strings contain the same letters with the same frequencies.
Find the Largest Array Element
Find the largest number in an array without using a built-in maximum function.
Find the Second-Largest Element
Find the second-largest distinct number in an array.
Remove Duplicate Array Elements
Create an array containing only unique elements.
Sort an Array
Sort a numeric array in ascending order without using a built-in sorting function.
Level 4 · Intermediate CFML Logic
Q31–40Structures, queries, dates, and practical ColdFusion problem-solving.
Frequency of Array Elements
Given an array of numbers, count the occurrences of each number using a CFML struct.
Find Missing Number
An array contains distinct numbers from 1 to N, with one number missing. Find it.
Find Duplicate Numbers
Find all duplicate values in an array.
Move Zeros to the End
Move all zeros to the end of an array while preserving the order of other values.
Merge Two Arrays
Merge two arrays and remove duplicates without using a built-in deduplication function.
Flatten a Nested Array
Convert a nested numeric array into a single-level array.
Word Frequency
Count the frequency of each word in a sentence, ignoring case.
Second-Highest Salary
Given employee query data, find the second-highest distinct salary.
Group Records by Department
Group employee records by department using CFML structures and arrays.
Date Difference
Calculate the number of days between two dates and handle dates in reverse order.
Level 5 · Advanced and Real-World Logic
Q41–50API handling, database logic, security, optimization, and application design.
Pagination Logic
Given 237 records and 10 records per page, calculate total pages, offset, and current-page records.
Validate Nested Data
Validate a nested CFML struct against required fields and expected data types.
Find Missing or Extra API Fields
Compare an API response struct against an expected list of keys and identify missing and unexpected keys.
Retry Failed API Requests
Design retry logic for a failed HTTP API request, with a maximum of three attempts and increasing delays.
Cache Expiration
Build logic that returns cached data if valid and refreshes it after expiration.
Detect Duplicate Records
Identify duplicate records by email address while handling case differences and surrounding whitespace.
Transaction Rollback
Use cftransaction to ensure multiple database changes roll back if one operation fails.
Prevent SQL Injection
Rewrite an unsafe dynamic SQL query using cfqueryparam and explain why it is safer.
Concurrent Request Safety
Design logic to prevent two simultaneous requests from updating the same inventory count incorrectly.
Optimize a Large Loop
Process 100,000 records efficiently, minimizing unnecessary nested loops and repeated calculations.
- Write your solution in CFScript, not tag-based syntax, unless a question specifically calls for tags.
- Avoid built-in shortcut functions when a question explicitly asks you to implement the logic yourself.
- Test normal inputs, edge cases, and invalid inputs, not just the happy path.
- Test your code against whichever ColdFusion or Lucee version you actually use day to day.