Shouldn’t this infintely loop?

Updated on January 1, 2019 in [A] Brackeys Courses
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on January 1, 2019

The code gives the same output even if I dont write numberofattempts++.Why tho?

Random numgen = new Random();
int numberofattempts = 0;
int attempt= 0;

while (attempt!= 6)
attempt = numgen.Next(1, 7);
Console.WriteLine(“You rolled a: ” + attempt);



Shouldn’t it infnitely loop?

  • Liked by
0 on January 1, 2019

No. Why would it loop infinitely?
You’re looping until you roll a 6.
You don’t even do anything with the number of numberofattempts variable, so removing it doesn’t do anything either.

  • Liked by