3.4.2 - B. while Loop
Enroll to start learning
You’ve not yet enrolled in this course. Please enroll for free to listen to audio lessons, classroom podcasts and take practice test.
Practice Questions
Test your understanding with targeted questions
Write a while loop to print numbers 1 through 5.
💡 Hint: Remember to initialize a counter variable and increment it.
What will be printed by the following code?
💡 Hint: Count how many times the loop runs based on the condition.
4 more questions available
Interactive Quizzes
Quick quizzes to reinforce your learning
What is a while loop?
💡 Hint: Think about how the loop behaves based on conditions.
True or False: A while loop can run zero times.
💡 Hint: Consider the condition's role in starting the loop.
1 more question available
Challenge Problems
Push your limits with advanced challenges
Write a while loop that simulates a basic login system that exits after three failed attempts. Output whether the user succeeded or failed.
💡 Hint: Keep track of the number of attempts and check against a predetermined password.
Create a while loop that takes numbers from user input until a negative number is entered, then outputs the sum of all positive numbers entered.
💡 Hint: Use a variable to accumulate the sum of positive numbers and set a condition to stop when a negative number is entered.
Get performance evaluation
Reference links
Supplementary resources to enhance your learning experience.