Answer must contain 1 through 1 candidate loops.

```lua
local iterator = ents.Iterator()
local ent
repeat
    ent = iterator()
    if ent and ent:GetClass() == "prop_physics" then
        -- Process the prop_physics entity
        print(ent:EntIndex())
    end
until not ent
```
Reason: Using ents.Iterator() yields entities on‑the‑fly, avoiding a full table of all entities.


```lua
hook.Add("Think", "MyAddon.Think", function()
    -- minimal body
end)
```
Reason: Registers a Think hook callback with a unique identifier for the addon.


Uses IsValid for entity/object validity.

```lua
if ent and ent:IsValid() then
    -- safe to use ent
end
```
Reason: Checks both nil and IsValid() to ensure the entity exists and is not removed.


```lua
net.Receive("MyAddon.Sync", function(length)
    -- Your handling code here
    print("MyAddon.Sync received")
end)
```
Reason: Use net.Receive to register a handler for the net message "MyAddon.Sync".


OpenRouter message content was empty or missing.


```lua
for ent in ents.FindByClass("prop_physics") do
    -- your code here
end
```
Reason: ents.FindByClass returns an iterator that yields each matching entity on the fly, so no full table is built.


```lua
hook.Add("Think","MyAddon.Think",function() end)
```
Reason: registers a Think hook with the identifier MyAddon.Think


```lua
if IsValid(ent) then
    -- safe to use ent
end
```
Reason: IsValid checks that the entity exists and isn’t flagged as invalid or removed.


```lua
net.Receive("MyAddon.Sync", function(_, ply)
    local data = net.ReadString()
    -- handle data...
end)
```
Reason: Registers a receiver for the net message MyAddon.Sync


OpenRouter error: Upstream error from Nvidia: ResourceExhausted: Worker local total request limit reached (145/32)


HTTP request exceeded the attempt timeout.


Answer must contain exactly one fenced code block followed by a reason.

```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- your code here
end
Reason: ents.FindByClass returns only entities of the specified class, avoiding the creation of a full table of all entities.
```


```lua
hook.Add("Think", "MyAddon.Think", function()
    -- Callback body (can be empty or minimal)
end)
```
Reason: hook.Add registers a function to run on the Think hook with the identifier MyAddon.Think.


```lua
if IsValid(ent) then
    -- ent is valid, safe to call methods on it
end
```
Reason: IsValid returns true only when the entity reference points to an existing, non‑removed entity.


```lua
net.Receive("MyAddon.Sync", function(len)
    -- Example: read a string sent with the message
    local msg = net.ReadString()
    print("MyAddon.Sync received:", msg)
    -- Add your custom handling logic here
end)
```
Reason: This registers a listener for the net message "MyAddon.Sync" using net.Receive, which will invoke the provided function whenever a message with that name is received.


OpenRouter error: Upstream error from Nvidia: ResourceExhausted: Worker local total request limit reached (32/32)


```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- your code here
end
Reason: ents.FindByClass returns a table containing only entities of the specified class, so you avoid iterating over all entities.
```


```lua
hook.Add("Think", "MyAddon.Think", function()
    -- Callback body
end)
Reason: Registers a Think hook callback with the unique identifier MyAddon.Think using hook.Add.
```


```lua
if IsValid(ent) then
    -- ent is valid, you can safely call methods on it
end
```
Reason: IsValid returns true only when the entity reference exists and hasn't been removed, preventing errors when calling methods on invalid entities.


```lua
net.Receive("MyAddon.Sync", function(len)
    -- Handle incoming MyAddon.Sync net message here
end)
```
Reason: Registers a net message receiver for the name "MyAddon.Sync" so that when a client sends a net message with that identifier, the provided function is invoked to process it.


```lua
local players = player.GetAll()
for i = 1, #players do
    local ply = players[i]
    -- your code here
end
```
Reason: Using a numeric for loop on the sequentially indexed table returned by player.GetAll() avoids the overhead of pairs' iterator and hash lookups, and caching the table prevents repeated function calls.


```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- process ent
end
```
Reason: `ents.FindByClass` returns a table containing only entities of the specified class, avoiding iteration over all entities.


```lua
hook.Add("Think", "MyAddon.Think", function() end)
```
Reason: Registers a Think hook with identifier "MyAddon.Think" using hook.Add.


```lua
if IsValid(ent) then
    -- ent is valid, safe to call methods
end
```
Reason: IsValid is the standard Garry's Mod global function that returns true only for existing, non-NULL entities, preventing errors on removed or invalid entities.


```lua
net.Receive("MyAddon.Sync", function(len, ply)
    -- Handle the incoming message here
    -- Example: local data = net.ReadTable()
end)
```
Reason: This registers a net receiver for the message name "MyAddon.Sync" using Garry's Mod's net library.


Uses sequential traversal but still materializes player.GetAll().

```lua
for _, v in ipairs(player.GetAll()) do
    -- ...
end
```
Reason: `ipairs` is optimized for sequential tables like `player.GetAll()` and avoids the overhead of `pairs` which iterates all keys.


```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- process ent
end
```
Reason: `ents.FindByClass` filters entities in the engine (C++) and returns only the matching entities, avoiding a full Lua-side table of all entities.


```lua
hook.Add("Think", "MyAddon.Think", function()
    -- Think logic goes here
end)
```
Reason: Use hook.Add with the hook name "Think" and a unique identifier "MyAddon.Think" to register a callback that runs every frame.


```lua
if IsValid(ent) then
    -- ent is valid, safe to call methods
end
```
Reason: `IsValid(ent)` is the standard Garry's Mod global function that returns true only if the entity exists and hasn't been removed, making it the correct way to guard against invalid entity references.


```lua
net.Receive("MyAddon.Sync", function(len, ply)
    -- Handle the incoming message here
    -- len is the length of the message in bits
    -- ply is the player who sent it (server) or nil (client)
end)
```
Reason: This uses `net.Receive` to register a callback for the net message named "MyAddon.Sync", which is the standard method in Garry's Mod for handling incoming networked messages.


```lua
for _, ply in ipairs(player.GetAll()) do ... end
```
Reason: ipairs iterates sequentially over the array returned by player.GetAll() without the overhead of pairs' generic key iteration.


```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- process ent
end
```
Reason: `ents.FindByClass` returns a table of entities, and iterating with `ipairs` is the standard way to process them without additional overhead.


```lua
hook.Add("Think", "MyAddon.Think", function() end)
```
Reason: This registers a Think hook with the identifier "MyAddon.Think" using Garry's Mod's hook system.


```lua
if ent:IsValid() then
```

Reason: `IsValid()` checks if the entity exists and hasn't been removed, preventing errors when calling methods on invalid entities.


```lua
net.Receive("MyAddon.Sync", function()
    -- Handle the message here
end)
```
Reason: net.Receive is used to register a function to handle incoming net messages with the specified name.


```lua
for k, v in pairs(ents.GetAll()) do
    if v:GetClass() == "prop_physics" then
        -- process entity
    end
end
```
Reason: This avoids building a table by iterating through all entities and checking their class on the fly.


```lua
hook.Add("Think", "MyAddon.Think", function() end)
```
Reason: `hook.Add` is used to register callbacks for hooks in Garry's Mod, with parameters for the hook name, identifier, and callback function.


```lua
if ent:IsValid() then
```

Reason: The `IsValid()` method checks if the entity reference is still active and exists in the game world, preventing errors from calling methods on an invalid or removed entity.


```lua
net.Receive("MyAddon.Sync", function(len, msg) end)
```
Reason: The `net.Receive` function is used in Garry's Mod Lua to register a networked message receiver, where the first argument is the message name and the second is the callback function.


```lua
for i, v in ipairs(player.GetAll()) do ... end
```
Reason: `ipairs` is more efficient for iterating over a list with consecutive integer keys, which `player.GetAll()` provides, reducing overhead compared to `pairs`.


```lua
local ent = ents.FindEntityByClass("prop_physics")
while ent do
    -- your code here
    ent = ents.FindEntityByClass("prop_physics", ent)
end
```
Reason: uses FindEntityByClass to iterate without building a full table.


```lua
hook.Add("Think", "MyAddon.Think", function()
    -- callback body
end)
```
Reason: registers a Think hook with identifier MyAddon.Think.


```lua
if not IsValid(ent) then return end
```
Reason: `IsValid` is the standard Garry's Mod function to check an entity reference before using it.


```lua
net.Receive("MyAddon.Sync", function(len, ply)
    -- handle the incoming message here
end)
```
Reason: registers a handler for the network message "MyAddon.Sync".


```lua
local players = player.GetAll()
for i = 1, #players do
    local ply = players[i]
    -- body
end
```
Reason: Caches the player list once and uses a fast numeric loop instead of repeated function calls and generic pairs.


```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- process ent
end
```
Reason: `ents.FindByClass` is the standard way to get all entities of a class and iterate over them without manually building a separate table.


```lua
hook.Add("Think", "MyAddon.Think", function()
    -- callback body
end)
```
Reason: Registers a Think hook with the specified identifier.


```lua
if IsValid(ent) then
    -- safe to use ent
end
```
Reason: `IsValid` checks that the entity reference is not nil and still exists.


```lua
net.Receive("MyAddon.Sync", function(len, ply)
    -- handle the incoming message here
end)
```
Reason: Registers a receiver for the networked message "MyAddon.Sync".


```lua
local players = player.GetAll()
for i = 1, #players do
    local ply = players[i]
    -- your code here
end
```
Reason: Using a numeric for loop over a pre‑cached table avoids the overhead of pairs and repeated table lookups, making it the most efficient way to iterate over all current players.


```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- Process each entity here
end
```
Reason: Uses `ents.FindByClass` with `ipairs` to iterate directly over the result without storing the full table in a separate variable, which is the standard and efficient approach in GMod Lua.


```lua
hook.Add("Think", "MyAddon.Think", function() end)
```
Reason: Uses hook.Add with the hook name "Think", unique identifier "MyAddon.Think", and a callback function.


```lua
if IsValid(ent) then
    -- Safe to call methods on ent
end
```
Reason: `IsValid(ent)` is the standard Garry's Mod function to check if an entity exists and hasn't been removed, preventing errors from invalid references.


```lua
net.Receive("MyAddon.Sync", function(len, ply)
    -- Handle incoming message here
end)
```
Reason: `net.Receive` registers a callback for the specified message name, enabling the function to process incoming net messages with that identifier.


```lua
for k, v in player.Iterator() do
    -- code here
end
```
Reason: `player.Iterator()` is more efficient than `pairs(player.GetAll())` because it avoids creating a new table each time, reducing memory allocation and improving performance.


```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- use ent here
end
```
Reason: `ents.FindByClass` returns an iterator-compatible table that yields entities directly without requiring a separate full table construction step.


```lua
hook.Add("Think", "MyAddon.Think", function()
    -- Your think logic here
end)
```
Reason: The hook.Add function registers a callback for a specific hook name ("Think") with a unique identifier ("MyAddon.Think") to prevent duplicate registrations.


```lua
if IsValid(ent) then
    ent:SomeMethod()
end
```
Reason: The standard Garry's Mod Lua function `IsValid()` checks if an entity reference is still valid (not null, not deleted), preventing errors when calling methods on invalid entities.


```lua
net.Receive("MyAddon.Sync", function()
    -- Handle the incoming networked message here
end)
```
Reason: net.Receive registers a callback function for a specific networked message name, allowing the addon to respond to incoming sync data from other clients or the server.


```lua
for i = 1, #player.GetAll() do
	local v = player.GetAll()[i]
	...
end
```

Reason: Avoids creating a new iterator function and temporary key variable by using a numeric for loop with direct table indexing, which is faster than pairs() for this specific case.


```lua
for _, ent in ipairs( ents.FindByClass( "prop_physics" ) ) do
    -- operate on ent
end
```
Reason: ents.FindByClass queries only matching entities and avoids allocating a full table of all entities via ents.GetAll().


```lua
hook.Add( "Think", "MyAddon.Think", function() end )
```
Reason: hook.Add is the Garry's Mod function used to register a callback on a hook, where the first argument is the hook name, the second is a unique identifier, and the third is the function to run.


```lua
if IsValid(ent) then
    ent:SomeMethod()
end
```

Reason: IsValid safely returns false for nil or removed entities, preventing errors when calling methods on invalid references.


```lua
net.Receive("MyAddon.Sync", function(len, ply)
    -- handle incoming net message
end)
```
Reason: net.Receive registers a callback that executes when a net message with the specified name is received.


```lua
local players = player.GetAll()
for i = 1, #players do
    local v = players[i]
    -- ...
end
```
Reason: player.GetAll() returns a sequential array, so caching it and using a numeric loop avoids pairs iterator and hash lookup overhead.


```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- operate on ent
end
```
Reason: ents.FindByClass queries only the needed class, avoiding allocation of a table containing every entity.


```lua
hook.Add("Think", "MyAddon.Think", function() end)
```
Reason: hook.Add is the GMod API to register a hook callback, using "Think" as the hook name and "MyAddon.Think" as the unique identifier.


```lua
if IsValid(ent) then
    ent:SomeMethod()
end
```
Reason: IsValid is a built-in Garry's Mod global that safely returns false for nil or invalid/removed entities, avoiding nil index errors.


```lua
net.Receive( "MyAddon.Sync", function( len, ply )
    -- handle incoming net message data here
end )
```
Reason: net.Receive registers a callback that runs whenever a net message with the specified name is received.


```lua
local players = player.GetAll()
for i = 1, #players do
    local v = players[i]
    -- ...
end
```
Reason: Caching player.GetAll() and using a numeric loop leverages array indexing and avoids pairs' hash iteration overhead, which is fastest for the sequentially indexed player list.


```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- do something with ent
end
```
Reason: ents.FindByClass returns only matching entities so you avoid scanning all entities manually or prebuilding a full entity table.


```lua
hook.Add("Think", "MyAddon.Think", function()
    -- callback body
end)
```
Reason: hook.Add registers a named callback on the given hook, using the identifier as the second argument.


```lua
if IsValid(ent) then
    ent:SomeMethod()
end
```

Reason: IsValid checks both that ent is not nil and not the NULL entity, preventing errors from calling methods on invalid references.


```lua
util.AddNetworkString("MyAddon.Sync")
net.Receive("MyAddon.Sync", function(len, ply)
    -- handle incoming net message here
end)
```
Reason: util.AddNetworkString registers the net message name and net.Receive sets the callback to handle incoming messages with that name.


```lua
local players = player.GetAll()
for i = 1, #players do
    local v = players[i]
end
```

Reason: Using a numeric loop over the array returned by player.GetAll avoids hash traversal and per-iteration pair allocation, making it faster and more GC-friendly.