Stopping criterion
A stopping criterion is a condition or rule that determines when a process, computation, or sequence of actions should end.
Modern C, Third Edition
A condition is an expression whose evaluated value controls conditional or iterative execution in C.
- How it is used
- Controls loop continuation and recursive termination, and governs whether a waiting thread still has reason to wait.
- How deep it goes
- Works through loop test placement, internal breaks, recursive termination, and condition-variable rechecks without deriving when an approximation converges.
- Examples
- Uses bounded and countdown loops, a precision-limited inverse approximation, and a recursive greatest-common-divisor function.
- What you can do after
- Build it from scratch: choose and place a loop or recursive exit test, then recheck a thread’s condition after waiting.
Read how Modern C, Third Edition explains stopping criterion →
Grokking Machine Learning
A criterion that prevents a decision-tree node from being split further.
- How it is used
- Controls when recursive decision-tree construction should stop to limit overfitting.
- How deep it goes
- Defines four hyperparameterized conditions but defers their detailed tuning to grid search.
- Examples
- Uses an app-recommendation dataset whose users are split by age and platform into increasingly pure leaves.
- What you can do after
- Apply it by setting sample, impurity-improvement, leaf-size, or maximum-depth hyperparameters.
Read how Grokking Machine Learning explains stopping criterion →
Modern C
A controlling expression is an expression whose value determines the path taken by a conditional or other control-flow construct.
- How it is used
- Controls when C loops continue, when recursion returns, and whether a waiting thread should wait again.
- How deep it goes
- Works through loop and recursive checks, then distinguishes a thread’s condition expression from its condition variable.
- Examples
- Uses a five-iteration for loop, recursive greatest-common-divisor calculation, and a thread that rechecks whether work remains.
- What you can do after
- Diagnose/debug with it: distinguish a missing recursive termination check from a valid loop condition, and recheck conditions after thread waits.
Grokking Algorithms, Second Edition
A base case is the terminating condition of a recursive definition or function that can be solved without another recursive invocation.
- How it is used
- Stops recursive functions from calling themselves indefinitely and gives divide-and-conquer algorithms a smallest problem to solve directly.
- How deep it goes
- Defines the base case, traces it in code, and gives a procedure for choosing one; leaves the land-division proof aside.
- Examples
- Uses a countdown that runs past zero without a return, plus empty and one-element arrays that quicksort returns unchanged.
- What you can do after
- Build it from scratch in a recursive countdown, then identify direct-return cases when reducing larger problems.
Read how Grokking Algorithms, Second Edition explains stopping criterion →
Grokking AI Algorithms, Second Edition
A stopping condition is a rule that determines when an iterative algorithm terminates.
- How it is used
- Determines when genetic, ant colony, and particle swarm searches end and return a best-found solution.
- How deep it goes
- Details fixed limits, target fitness, and stagnation, but shows a fixed-iteration loop rather than an adaptive-stop implementation.
- Examples
- Uses repeated ant tours, a fitness-100 plateau from iterations 20 to 30, and Python iteration loops.
- What you can do after
- Operate/configure it: Choose a limit or fitness-based rule while weighing solution quality against computation time.
Read how Grokking AI Algorithms, Second Edition explains stopping criterion →
Classic Computer Science Problems in Swift: Essential techniques for practicing programmers
The terminating condition of a recursive algorithm that can be solved directly without another recursive invocation.
- How it is used
- Prevents infinite recursion by returning directly for inputs that require no further recursive invocation.
- How deep it goes
- Explains base and recursive cases with Fibonacci and Hanoi, then stops short of formal termination proofs.
- Examples
- Uses Fibonacci values and one-disc Towers of Hanoi moves as concrete stopping conditions.
- What you can do after
- Build recursive Swift functions by identifying direct inputs and separating them from recursive cases.
AI Agents in Action, Second Edition
A stop condition is a rule that determines when an iterative agent process must terminate.
- How it is used
- Controls when research, task, or other iterative agents exit instead of continuing toward a goal.
- How deep it goes
- Defines a layered termination gate with hard, budget, goal, quality, and stagnation checks, but does not provide complete implementation code.
- Examples
- Uses iteration caps, token budgets, goal declarations, evaluator scores, semantic-overlap checks, and a MAX_TURNS = 3 planning example.
- What you can do after
- Operate/configure iterative agents with layered exits, hard ceilings, cost controls, and safeguards against repeated unproductive work.
Read how AI Agents in Action, Second Edition explains stopping criterion →
Get Programming: Learn to code with Python
A Boolean-valued test that determines which execution path a conditional construct should take.
- How it is used
- Guides conditional choices and controls whether repeated commands run again.
- How deep it goes
- Explains repeated condition checks, condition updates, and infinite-loop risks, while stopping short of formal debugging methods.
- Examples
- Uses phone selection, lather-rinse repetition, and a secret-word guessing game to demonstrate conditions and termination.
- What you can do after
- Build it from scratch by writing conditions that select paths, repeat work, and stop loops at the intended point.
Read how Get Programming: Learn to code with Python explains stopping criterion →
Optimization Algorithms: AI techniques for design, planning, and control problems
A condition that determines when an iterative algorithm should stop.
- How it is used
- Defines when search, optimization, robotics, genetic, and swarm algorithms finish their iterative work.
- How deep it goes
- Classifies goal, iteration, quality, stagnation, and resource limits, but does not develop general parameter-selection theory.
- Examples
- Uses robotic pick-and-place, 7-queens tabu search, genetic algorithm generations, and swarm iterations as concrete cases.
- What you can do after
- Operate/configure iterative searches by combining iteration, quality, stagnation, and resource limits.
Experimentation for Engineers
A stopping rule is a criterion that determines when an experiment or sequential decision process should terminate.
- How it is used
- Controls when bandit experimentation stops exploring and can promote the currently superior business-metric variant.
- How deep it goes
- Defines threshold and probability-based rules, explains exploration trade-offs, and accounts for sampling precision and practical significance.
- Examples
- Uses decaying epsilon with a 0.01 threshold and Thompson sampling with p_stop = 0.95 and minimum per-arm sampling.
- What you can do after
- Operate/configure bandit experiments by selecting exploration thresholds, tuning exploration duration, and checking minimum-sample requirements.
Read how Experimentation for Engineers explains stopping criterion →
Build a Reasoning Model (From Scratch)
A criterion that terminates generation when met, such as encountering an end-of-sequence token.
- How it is used
- Terminates autoregressive text generation when a completion marker or token limit is reached.
- How deep it goes
- Defines the condition and shows where it breaks the loop, but stops short of broader sampling strategies.
- Examples
- Uses <|endoftext|>, tokenizer.eos_token_id, and a 100-token prompt run to demonstrate termination.
- What you can do after
- Operate generation with an EOS-aware loop that stops and streams decoded tokens safely.
Read how Build a Reasoning Model (From Scratch) explains stopping criterion →
Related concepts
- recursionpart of · Recursion is a computational technique in which a definition or procedure refers to or invokes the same definition or procedure, directly or indirectly.
- loopconfigures · A loop is a programming control-flow construct that repeatedly executes a block of instructions according to an iteration rule or continuation condition.
- conditional logicused by · Conditional logic is a programming technique that selects execution paths, actions, or result values according to evaluated conditions.
- thresholdconfigured by · A threshold is a boundary value against which a quantity is compared to determine whether a condition is met or an action or decision is triggered.
- token limitconfigured by · A token limit is a configured upper bound on the number of tokens a model or text-processing operation may accept, process, or generate.
- final stateaddresses · A final state is the endpoint of a relevant process, scenario, interaction, or sequence, after which it does not continue through its normal progression.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.










