Harbor

branch main
showing the latest snapshot on main
loop_control.luma 682 B · Plain text
gpu/shader/tests/shaders/loop_control.luma 0644 Raw
-- Test break and continue in for/while loops

@entry(fragment)
function shade(value: float) -> vec4
	var result = 0.0

	-- Test continue: skip even iterations
	for i = 0, 10 do
		if i % 2 == 0 then
			continue
		end
		result = result + float(i)
	end

	-- Test break: exit early
	var total = 0.0
	for j = 0, 100 do
		if j > 5 then
			break
		end
		total = total + 1.0
	end

	-- Test break in while loop
	var k = 0
	while k < 100 do
		if k > 10 then
			break
		end
		k = k + 1
	end

	-- Test continue in while loop
	var sum = 0.0
	var m = 0
	while m < 10 do
		m = m + 1
		if m == 5 then
			continue
		end
		sum = sum + 1.0
	end

	return vec4(result + total + sum, 0.0, 0.0, 1.0)
end