Mastery 19. Use of loops with “while”… Mastery 20. Use of loops with “for”… And here my video:![]()
Basic use of While loops, but it does work.

Hi again there! Here is my video for #Mastery19 & #Mastery20:

Hello everybody, this post is to explain the basic use of while loops and for loops. While is a loop that will be performed if the conditions inside its definition is true. Yes, you are right… again boolean value. If the condition inside the while returns the value true then the code under the while […]![]()
On this mastery I’m going to show you what “while” loop in C++ is and how to use it.
The while loop consists of something happens WHILE a condition is given. For example: WHILE x is greater or equal than 0, something will happen, and this process will continue to happen WHILE this condition is true.
For the purpose of these mastery, we will use a function and a while loop to continue printing a character while the condition is true.
We want to print n amount of hashtags (#) because we really LOVE hashtags. So the user will input the amount of hashtags he wants to print and the program should be able to print that amount of hashtags. So, do as follows:
- Write our “basic code” and leave some space to write a function as we learn on masteries 11 and 12.
- Write a function of type CHAR (because we will use characters) that prints a # when you return its value.
- Inside int main (), declare the variable, and ask the user for it.
- Now, we will use the WHILE loop. So until now, your code should look something like this:

Now, for the WHILE loop, we want to ask the user for an x amount of times the character # will print, so we need this:

The code inside the while loop will continue to happen until x = 0. So your code should work like this:

And that’s about it, you now know how to use while loop with a function, congrats!


Hi! This was my first youtube video for Ken’s class called Masteries TC1017 While loop & If![]()





