DevLearningTools

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–10

Variables, conditions, loops, and basic calculations.

01

Even or Odd

Write a CFML program to check whether a given number is even or odd.

02

Positive, Negative, or Zero

Determine whether a number is positive, negative, or zero.

03

Largest of Two Numbers

Find the largest of two numbers without using a built-in maximum function.

04

Largest of Three Numbers

Find the largest of three numbers using conditional statements.

05

Swap Two Variables

Swap two variable values with and without using a temporary variable.

06

Sum of Natural Numbers

Calculate the sum of numbers from 1 to N using a loop.

07

Multiplication Table

Print the multiplication table of a given number from 1 to 10.

08

Factorial

Calculate the factorial of a number using a loop.

09

Leap Year

Check whether a given year is a leap year.

10

Divisibility Check

Check whether a number is divisible by both 3 and 5.

Level 2 · Number-Based Logic

Q11–20

Mathematical operations, number properties, and algorithms.

11

Reverse a Number

Reverse the digits of a number. Example: 1234 → 4321.

12

Palindrome Number

Check whether a number reads the same forward and backward. Example: 121.

13

Prime Number

Determine whether a number is prime.

14

Prime Numbers in a Range

Print all prime numbers between 1 and 100.

15

Fibonacci Series

Generate the first N terms of the Fibonacci sequence.

16

Sum of Digits

Calculate the sum of the digits of a number. Example: 1234 → 10.

17

Count Digits

Count the number of digits in an integer.

18

Armstrong Number

Check whether a number is an Armstrong number. Example: 153 = 1³ + 5³ + 3³.

19

GCD and LCM

Calculate the greatest common divisor and least common multiple of two numbers.

20

Perfect Number

Check whether a number equals the sum of its positive divisors excluding itself. Example: 28.

Level 3 · Strings and Arrays

Q21–30

String functions, arrays, loops, and data manipulation.

21

Reverse a String

Reverse a string without using a built-in reverse function.

22

Palindrome String

Check whether a string is a palindrome, ignoring letter case.

23

Count Vowels and Consonants

Count vowels and consonants in a given string.

24

Character Frequency

Count how many times each character appears in a string.

25

Remove Duplicate Characters

Remove repeated characters from a string while preserving order.

26

Anagram Check

Check whether two strings contain the same letters with the same frequencies.

27

Find the Largest Array Element

Find the largest number in an array without using a built-in maximum function.

28

Find the Second-Largest Element

Find the second-largest distinct number in an array.

29

Remove Duplicate Array Elements

Create an array containing only unique elements.

30

Sort an Array

Sort a numeric array in ascending order without using a built-in sorting function.

Level 4 · Intermediate CFML Logic

Q31–40

Structures, queries, dates, and practical ColdFusion problem-solving.

31

Frequency of Array Elements

Given an array of numbers, count the occurrences of each number using a CFML struct.

32

Find Missing Number

An array contains distinct numbers from 1 to N, with one number missing. Find it.

33

Find Duplicate Numbers

Find all duplicate values in an array.

34

Move Zeros to the End

Move all zeros to the end of an array while preserving the order of other values.

35

Merge Two Arrays

Merge two arrays and remove duplicates without using a built-in deduplication function.

36

Flatten a Nested Array

Convert a nested numeric array into a single-level array.

37

Word Frequency

Count the frequency of each word in a sentence, ignoring case.

38

Second-Highest Salary

Given employee query data, find the second-highest distinct salary.

39

Group Records by Department

Group employee records by department using CFML structures and arrays.

40

Date Difference

Calculate the number of days between two dates and handle dates in reverse order.

Level 5 · Advanced and Real-World Logic

Q41–50

API handling, database logic, security, optimization, and application design.

41

Pagination Logic

Given 237 records and 10 records per page, calculate total pages, offset, and current-page records.

42

Validate Nested Data

Validate a nested CFML struct against required fields and expected data types.

43

Find Missing or Extra API Fields

Compare an API response struct against an expected list of keys and identify missing and unexpected keys.

44

Retry Failed API Requests

Design retry logic for a failed HTTP API request, with a maximum of three attempts and increasing delays.

45

Cache Expiration

Build logic that returns cached data if valid and refreshes it after expiration.

46

Detect Duplicate Records

Identify duplicate records by email address while handling case differences and surrounding whitespace.

47

Transaction Rollback

Use cftransaction to ensure multiple database changes roll back if one operation fails.

48

Prevent SQL Injection

Rewrite an unsafe dynamic SQL query using cfqueryparam and explain why it is safer.

49

Concurrent Request Safety

Design logic to prevent two simultaneous requests from updating the same inventory count incorrectly.

50

Optimize a Large Loop

Process 100,000 records efficiently, minimizing unnecessary nested loops and repeated calculations.

HOW TO PRACTICE
  • 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.
Already comfortable with these? Try the senior-level set, architecture, DevOps, security, and system design.Advanced questions →