Added Ex 11-14: while loops
This commit is contained in:
parent
0bb89e3e41
commit
483fb97dfc
6 changed files with 129 additions and 1 deletions
24
14_while4.zig
Normal file
24
14_while4.zig
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
//
|
||||
// Continue expressions do NOT execute when a while loop stops
|
||||
// because of a 'break' statement.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// while (condition) : (continue expression){
|
||||
// if(other condition) break;
|
||||
// ...
|
||||
// }
|
||||
//
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() void {
|
||||
var n: u32 = 1;
|
||||
|
||||
// Oh dear! This while loop will go forever!?
|
||||
while (true) : (n+=1) {
|
||||
if(???) ???;
|
||||
}
|
||||
|
||||
// Result: we want n=4
|
||||
std.debug.print("n={}\n", .{n});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue