Check required conditions before running code that depends on them.

precondition Preconditions make the success path explicit and keep invalid inputs from reaching later calculations.

Requirement Check

count
requirement_check.lua
Replay: real traced execution (multi-file project)
local count = 3
local ok = count > 0
local nextValue = "blocked"

if ok then
  nextValue = tostring(count + 1)
end

print("count=" .. count)
print("ok=" .. tostring(ok))
print("nextValue=" .. nextValue)
local count = 0
local ok = count > 0
local nextValue = "blocked"

if ok then
  nextValue = tostring(count + 1)
end

print("count=" .. count)
print("ok=" .. tostring(ok))
print("nextValue=" .. nextValue)
local count = 5
local ok = count > 0
local nextValue = "blocked"

if ok then
  nextValue = tostring(count + 1)
end

print("count=" .. count)
print("ok=" .. tostring(ok))
print("nextValue=" .. nextValue)
  1. count ← 3, ok ← true, nextValue ← blocked

    1local count→ 3 = 3 --@count=0, 52local ok→ true = count3 > 03local nextValue→ blocked = "blocked"
  2. nextValue ← 4

    5if oktrue then6  nextValue→ 4 = tostring(count3 + 1)7end
  3. print("count=" .. count)

    9print("count=" .. count3)10print("ok=" .. tostring(oktrue))11print("nextValue=" .. nextValue4)
    outputcount=3
    ok=true
    nextValue=4
  1. count ← 0, ok ← false, nextValue ← blocked

    1local count→ 0 = 02local ok→ false = count0 > 03local nextValue→ blocked = "blocked"45if ok then6  nextValue = tostring(count + 1)7end89print("count=" .. count0)10print("ok=" .. tostring(okfalse))11print("nextValue=" .. nextValueblocked)
    outputcount=0
    ok=false
    nextValue=blocked
  1. count ← 5, ok ← true, nextValue ← blocked

    1local count→ 5 = 52local ok→ true = count5 > 03local nextValue→ blocked = "blocked"
  2. nextValue ← 6

    5if oktrue then6  nextValue→ 6 = tostring(count5 + 1)7end
  3. print("count=" .. count)

    9print("count=" .. count5)10print("ok=" .. tostring(oktrue))11print("nextValue=" .. nextValue6)
    outputcount=5
    ok=true
    nextValue=6