1 # From the GLSL 4.40 spec, section 6.4 (Jumps):
3 # The continue jump is used only in loops. It skips the remainder
4 # of the body of the inner most loop of which it is inside. For
5 # while and do-while loops, this jump is to the next evaluation of
6 # the loop condition-expression from which the loop continues as
9 # One way that do-while loops might be implemented is to convert them
10 # to infinite loops that terminate in a conditional break (this is
11 # what Mesa does). In such an implementation, an easy way to
12 # implement the proper behaviour of "continue" in a do-while loop is
13 # to replicate the conditional break at the site of the "continue".
14 # For example, this code:
23 # } while (condition);
25 # would get translated to:
40 # However, we must be careful in making this transformation if the
41 # "continue" occurs inside a switch statement, since "break" inside a
42 # switch statement normally exits the switch statement, not the
45 # This test verifies that "continue" behaves properly when invoked
46 # inside a switch statement which is itself inside a do-while loop.
55 gl_Position = gl_Vertex;
60 do { // 1st iteration 2nd iteration
62 switch (w) { // Jump to case 1 Jump to case 2
67 continue; // Jump to (w < 2)
69 ++y; // (this case is never executed)
72 ++z; // z <- 1 skipped
73 } while (w < 2); // true false
75 // The loop should execute for two iterations, so w should be 2. X
76 // should be incremented on the first iteration only, so it should
77 // be 1. Y should never be incremented (since w never reaches 3),
78 // so it should be 0. The "continue" should skip ++z on the second
79 // iteration, so z should be 1.
80 if (w == 2 && x == 1 && y == 0 && z == 1)
81 gl_FrontColor = vec4(0.0, 1.0, 0.0, 1.0);
83 gl_FrontColor = vec4(1.0, 0.0, 0.0, 1.0);
90 gl_FragColor = gl_Color;
95 probe all rgba 0.0 1.0 0.0 1.0