Hi I am doing ziglings 47 https://github.com/ratfactor/ziglings/blob/main/exercises/047_methods.zig#L84. Here is the code
var aliens = [_]Alien{
Alien.hatch(2),
Alien.hatch(1),
Alien.hatch(3),
Alien.hatch(3),
Alien.hatch(5),
Alien.hatch(3),
};
var aliens_alive = aliens.len;
const heat_ray = HeatRay{ .damage = 7 }; // We've been given a heat ray weapon.
// We'll keep checking to see if we've killed all the aliens yet.
while (aliens_alive > 0) {
aliens_alive = 0;
// Loop through every alien by reference (* makes a pointer capture value)
for (&aliens) |*alien| {
Can someone help me understand what the syntax is for that for loop with the & and *. I tried removing them and just doing
for (aliens) |alien| {
heat_ray.zap(&alien);
But that isnt valid because its expecting a const alien apparently but the signature is *Alien. Why does this not work and what is actually happening here with this loop?