Professional Documents
Culture Documents
While Loop Practice-1
While Loop Practice-1
While Loop Practice-1
• 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.
Syntax
Initializations or assignment to the pre-declared variable
while(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:
Python:
Java:
Problem 2:
Java:
Problem 3:
Python:
Java:
Problem 4:
Python:
Java:
Problem 5:
Python:
Java:
Problem 6:
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: