gmod_src: Added continue keyword to Lua

Revision 649
Added continue keyword to Lua Changed Files:
[ul]
[li]trunk/src_garrysmod/public/Lua/llex.c [/li][li]trunk/src_garrysmod/public/Lua/llex.h [/li][li]trunk/src_garrysmod/public/Lua/lparser.c[/li][/ul]

Committed By Garry Newman

Nice, thanks!

:woop:

:neckbeard:

Finally, gonna re-write my code for this, looks alot nicer :3:

Can anybody explain how this is used?

[lua]for i=1, 10

if ( i < 5 ) then continue end

print( i )

end[/lua]

would print 5 onwards

[editline]05:21PM[/editline]

Also, real world example…

[lua]function gmsave.EntitySaveList( ents )

local tabEnts = {}
local savedEnts = {}
local SaveName = 1

for k, v in pairs( ents ) do

	if ( !IsValid( v ) ) then continue end
	
	local t = gmsave.EntitySave( v )
	
	if ( !gmsave.ShouldSaveEntity( v, t ) ) then continue end
	
	v.GMSaveName = "ent" .. SaveName;
	tabEnts[ v.GMSaveName ] = t;
	savedEnts[ v.GMSaveName ] = v
	
	
	SaveName = SaveName + 1
	
end

return tabEnts, savedEnts;

end[/lua]

It skips to the next iteration in the loop.

[lua]for i=1, 5 do
if i == 3 then
continue
end

Msg(i, ", ")

end[/lua]

The output would be "1, 2, 4, 5, ".

Ah I see thanks for explaining :3

continue is useful thanks garry.

Wow fuck yes, I was talking to a shitload of people about howto achieve this like a week ago, it’s like you read my mind! :smiley:

Awesome. No more if blocks in entire loops.

:love:

Yes :razz:!

Fuck yeah, this is amazing

Nice to see this addition. Still unclear to me, why lua hasn’t this from default.

it should be named “skip” :smiley:

Awesome!

Garry rewrote Lua to work with CStyle syntax, maybe he removed it then?

Lua has never had native continue afaik.

-Snip-