my ziglings
0

Configure Feed

Select the types of activity you want to include in your feed.

fix loop else clause explanation

Ziyi Yan (Apr 22, 2022, 5:50 PM -0700) ad5d57be 708b6fc3

+2 -2
+2 -2
exercises/062_loop_expressions.zig
··· 13 13 // But what value is returned from a loop if a break statement is 14 14 // never reached? We need a default expression. Thankfully, Zig 15 15 // loops also have 'else' clauses! As you might have guessed, the 16 - // else clause is evaluated once a while condition becomes false 17 - // or a for loop runs out of items. 16 + // 'else' clause is evaluated when: 1) a 'while' condition becomes 17 + // false or 2) a 'for' loop runs out of items. 18 18 // 19 19 // const two: u8 = while (true) break 2 else 0; // 2 20 20 // const three: u8 = for ([1]u8{1}) |f| break 3 else 0; // 3