var to const when posssible
parent
f09a87c348
commit
d2d3dfa277
@ -1,16 +1,16 @@
|
||||
//
|
||||
// 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");
|
||||
|
||||
pub fn main() void {
|
||||
var discount = true;
|
||||
const discount = true;
|
||||
|
||||
// Please use an if...else expression to set "price".
|
||||
// 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});
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
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
|
||||
< 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
|
||||
< 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