A while loop statement in Java programming language repeatedly executes a target statement as long as a given condition is true.
Syntax :
while(Boolean_expression) {
// Statements
}
Here, statement(s) may be a single statement or a block of statements. The condition may be any expression, and true is any non zero value.
When executing, if the boolean_expression result is true, then the actions inside the loop will be executed. This will continue as long as the expression result is true.
When the condition becomes false, program control passes to the line immediately following the loop.
#input # output
a=6 quantity of commodity=
b=int(input("quantity of commodity=")) sampoo
i=1 sampoo
while i <= b : sampoo
if i>a: sampoo
print("hello") sampoo
break sampoo
print('sampoo') hello (it is printed when a<=7)
i+=1 thank you for coming
print("thank you for coming")
A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.
Syntax :
do {
// Statements
}while(Boolean_expression);
Notice that the Boolean expression appears at the end of the loop, so the statements in the loop execute once before the Boolean is tested.
If the Boolean expression is true, the control jumps back up to do statement, and the statements in the loop execute again. This process repeats until the Boolean expression is false.
public class Test {
public static void main(String args[]) {
int x = 10;
do {
System.out.print("value of x : " + x );
x++;
System.out.print("
");
}while( x < 20 );
}
}
# There are 2 types of loops in python
# while loops and for loops
# a while loops continues for an indefinite amount of time
# until a condition is met:
x = 0
y = 3
while x < y:
print(x)
x = x + 1
>>> 0
>>> 1
>>> 2
# The number of iterations (loops) that the while loop above
# performs is dependent on the value of y and can therefore change
######################################################################
# below is the equivalent for loop:
for i in range(0, 3):
print(i)
>>> 0
>>> 1
>>> 2
# The for loop above is a definite loop which means that it will always
# loop three times (because of the range I have set)
# notice that the loop begins at 0 and goes up to one less than 3.
A while loop statement in Java programming language repeatedly executes a target statement as long as a given condition is true.
Syntax :
while(Boolean_expression) {
// Statements
}
The do...while statement creates a loop that executes a specified statement until the test condition evaluates to false. The condition is evaluated after executing the statement, resulting in the specified statement executing at least once.
The do...while statement creates a loop that executes a specified statement until the test condition evaluates to false. The condition is evaluated after executing the statement, resulting in the specified statement executing at least once.
<?php
$num=1;
while($num<=5)
{
echo"The number is ".$num."<br>";
$num++;
}
//======output=====
/*
The number is 1
The number is 2
The number is 3
The number is 4
The number is 5
*/
?>
<?php
$num=1;
do{
$num++;
echo"The number is ".$num."<br>";
}
while($num<=5);
//======output=====
/*
The number is 2
The number is 3
The number is 4
The number is 5
The number is 6
*/
?>
while(<condition here>)
{
do this;
increment or decrement;
}
//number variable must be initilize before run the program
/*
while (number <= 10)
{
print(number);
number++;
}
*/
while True:
print("A period of time.")
# "we chatted for a while"
print("Similar: time spell stretch stint")
print("at the same time; meanwhile.")
# "he starts to draw. talking for a while"
"""
CONJUCTION :D
"""