Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Password Attempts | While and Do-While Loops: Control and Flexibility
C# Loops Practice

bookChallenge: Password Attempts

Opgave

Swipe to start coding

Strengthen your while loop skills by building a password entry system. Complete the following steps:

  • Use a while loop to process password attempts, stopping if the correct password is entered or if the maximum number of attempts is reached.
  • Try not use if, else, or break statements inside the loop.
  • On each attempt, print the password entered.
  • Print a message showing how many attempts remain after each incorrect guess.
  • When the correct password is entered, print a success message and stop further attempts.
  • If all attempts are used without entering the correct password, print an account locked message after the loop.

Løsning

Note
Note

In this task:

  • attempt is the current password guess from the attempts array, used for printing and comparison;
  • remaining counts how many tries are left, decreasing after each wrong password;
  • found is true when the correct password is entered, stopping the loop.

These variables let you manage attempts and stop the loop without using if, else, or break.

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 2. Kapitel 2
single

single

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

close

Awesome!

Completion rate improved to 5.56

bookChallenge: Password Attempts

Stryg for at vise menuen

Opgave

Swipe to start coding

Strengthen your while loop skills by building a password entry system. Complete the following steps:

  • Use a while loop to process password attempts, stopping if the correct password is entered or if the maximum number of attempts is reached.
  • Try not use if, else, or break statements inside the loop.
  • On each attempt, print the password entered.
  • Print a message showing how many attempts remain after each incorrect guess.
  • When the correct password is entered, print a success message and stop further attempts.
  • If all attempts are used without entering the correct password, print an account locked message after the loop.

Løsning

Note
Note

In this task:

  • attempt is the current password guess from the attempts array, used for printing and comparison;
  • remaining counts how many tries are left, decreasing after each wrong password;
  • found is true when the correct password is entered, stopping the loop.

These variables let you manage attempts and stop the loop without using if, else, or break.

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 2. Kapitel 2
single

single

some-alt