Noob Loop While: save iteration

I think the problem is that the program can not understand that the player p1 is increasing the level, how can I tell him that i is p1? sorry I'm a goat ... thank you

class Player{
var nome: String
var livello: Int8
var p1:Player
var ArrayPlayers : [Player] = [p1,p2,p3]

func inizioTurno(player: Player){
print("Turno giocatore (player.nome)"
print("Pesca carta")
print("Gioca carta")
player.livello += 1

func Gioco(array:[Player]){
repeat {
for i in array {
} while p1.livello > 3 }


If you want to mutate/change a value of a instance you must pass that as a reference by using inout in the func argument.

func inizioTurno(player: inout Player){ ... }
inzioTurno(player: &i)

The OP is using classes, not structs.

Are you sure “>” is what you want here?

1 Like

Ah, I completely missed (unconsciously assumed) that it would be a struct. It certainly looks like the condition is the error.

Maybe he wanted repeat { ... } while p1.level <= 3 ?

Thanks guys you're right the condition l I'm wrong serious .. thanks again