Merge pull request #329 from lorrding/refactor-var-to-const
Change `var` to `const` in some exercisespull/2/head
commit
2705e16c36
@ -1,16 +1,16 @@
|
|||||||
//
|
//
|
||||||
// If statements are also valid expressions:
|
// If statements are also valid expressions:
|
||||||
//
|
//
|
||||||
// var foo: u8 = if (a) 2 else 3;
|
// const foo: u8 = if (a) 2 else 3;
|
||||||
//
|
//
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
pub fn main() void {
|
pub fn main() void {
|
||||||
var discount = true;
|
const discount = true;
|
||||||
|
|
||||||
// Please use an if...else expression to set "price".
|
// Please use an if...else expression to set "price".
|
||||||
// If discount is true, the price should be $17, otherwise $20:
|
// If discount is true, the price should be $17, otherwise $20:
|
||||||
var price: u8 = if ???;
|
const price: u8 = if ???;
|
||||||
|
|
||||||
std.debug.print("With the discount, the price is ${}.\n", .{price});
|
std.debug.print("With the discount, the price is ${}.\n", .{price});
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
13c13
|
13c13
|
||||||
< var price: u8 = if ???;
|
< const price: u8 = if ???;
|
||||||
---
|
---
|
||||||
> var price: u8 = if (discount) 17 else 20;
|
> const price: u8 = if (discount) 17 else 20;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
32c32
|
32c32
|
||||||
< var answer: u8 = result;
|
< const answer: u8 = result;
|
||||||
---
|
---
|
||||||
> var answer: u8 = result orelse 42;
|
> const answer: u8 = result orelse 42;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
43c43
|
43c43
|
||||||
< var shuttle_weight: f16 = 907.18 * 2200;
|
< const shuttle_weight: f16 = 907.18 * 2200;
|
||||||
---
|
---
|
||||||
> var shuttle_weight: f32 = 907.18 * 2200.0;
|
> const shuttle_weight: f32 = 907.18 * 2200.0;
|
||||||
|
Loading…
Reference in New Issue