Use while-loop to avoid unnecessary break.
This commit is contained in:
parent
b9c2ae82d6
commit
aa5702a0a3
@ -93,17 +93,16 @@ fn main()
|
||||
};
|
||||
// the next (first) box the prisoner is to open is the one with his number (`i`)
|
||||
let mut next_box:usize = i as usize;
|
||||
// for every attempt the prisoner has (i.e. `size/2`)
|
||||
for _j in 0..(size/2)
|
||||
// while the prisoner still has attempts left AND he hasn't found his number
|
||||
while prisoner_i.attempts < size/2 && !prisoner_i.found
|
||||
{
|
||||
// count attempt
|
||||
prisoner_i.attempts += 1;
|
||||
// if the number inside the box is his number
|
||||
if boxes[next_box] == i
|
||||
{
|
||||
// assign `found` to true
|
||||
prisoner_i.found = true;
|
||||
// stop looking through more boxes.
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user