While Loop Practice-1

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

While Loop Practice

• While loop also known as sentinel-controlled loop.

• The value on which the loop terminates or breaks is known as Sentinel Value.

• Unknown iterations.

• When we don't know how many times the program will run when we will change the input.

• It is used in the cases when two terms are not equals.

• We don't know how many times our loop will execute.

Syntax
Initializations or assignment to the pre-declared variable

while(condition){

// set of instructions to perform the specific task

// change in the variable used in the condition

Example:
• I was waiting while he was eating
• I was buying while the amount isn't less or equals to 1000
• I was walking while they were talking
• I was watching the TV while my siblings were sleeping
• I was driving while he wasn't found

Syntax
while(2){

3,4 or 4,3

}
Example:
while(true){

int number = 2;

while(number < 5)

number *= 1;
Problem 1:

I was waiting while he was eating.

Python:

Java:
Problem 2:

I was buying while the amount isn't greater or equals to 1000.


Python:

Java:
Problem 3:

Converting decimal number to binary.

Python:

Java:
Problem 4:

Converting decimal to octal.

Python:

Java:
Problem 5:

Converting decimal number to custom number base less than 10.

Python:

Java:
Problem 6:

Converting Binary to Decimal.

Python:

Java:
Problem 7:

Guess a Number.

Python:
Java:

Problem 8:
Count numbers in a decimal.

Python:
Java:
Problem 9:
Reverse a Number.

Python:

Java:
Problem 10:

Prime Numbers.

Python:

Java:
Problem 11:

Palindrome Numbers.

Python:

Java:

You might also like