+ 1

Guys please any one say what is while loop

While loop

27th Oct 2019, 2:16 AM
THE INDUSTRY
THE INDUSTRY - avatar
4 odpowiedzi
+ 3
i just want to add onto what Eliya Ben Baruch said: it’s easiest to read it as “while n is less than 10” while n is less than 10, go inside the while loop and execute any statements inside. once they are executed, check again to see if n is less than 10. if n is still less than 10, go inside again. if n is 10 or more (10 is not less than 10), then skip the while loop.
27th Oct 2019, 3:00 AM
꧁༺ Jenspi ༻꧂
꧁༺ Jenspi ༻꧂ - avatar
+ 3
Hai.Let me try to explain. While loop is a basic programming construct in almost all general purpose programming languages to execute a particular block of code iteratively and until certain condition meets.For Ex: int i=1; while(i<=10) { print "Hai"; i++; } here, we print "Hai" 10 times.First the variable "i" is initialized to 1,Now while condition is checked against the values: while(1<=10) which is true, so it executes the block of code in while,starting from the first curly brace to the next curly brace which is end of the while block. So, It prints "Hai" and increments "i" value.So, i=2 now. The Process is: i=1 1<=10 is true so prints "Hai" and increments i, now i=2 2<=10 is true so prints "Hai" and increments i, now i=3 3<=10 is true so prints "Hai" and increments i, now i=4 4<=10 is true so prints "Hai" and increments i, now i=5 5<=10 is true so prints "Hai" and increments i, now i=6 6<=10 is true so prints "Hai" and increments i, now i=7 7<=10 is true so prints "Hai" and increments i, now i=8 8<=10 is true so prints "Hai" and increments i, now i=9 9<=10 is true so prints "Hai" and increments i, now i=10 10<=10 is true so prints "Hai" and increments i, now i=11 11<=10 is "False" so while loop exits. now,The statements after while loop gets executed. While loop is suitable when we don't know exactly how many times to execute a block. like: while(i<=n && n%i > k) or while(i+(k/3)-2) here each time calculation is done, based on the result,it is decided whether to execute the code in while block (if condition is true) or to skip the while block(if condition is evaluated to false). condition in while becomes to True when the arithmetic expression evaluated to any value other than zero(0).
27th Oct 2019, 3:00 AM
EAGALA BHANU PRAKASH
EAGALA BHANU PRAKASH - avatar
+ 2
Thank you so much bro
27th Oct 2019, 3:04 AM
THE INDUSTRY
THE INDUSTRY - avatar
+ 1
While loop gets a condition in its declaration. Like: int n = 5 While (n < 10) n++; This loop will if n is less than 10. But when n's value will be 10 the loop will stop.
27th Oct 2019, 2:51 AM
Eliya Ben Baruch
Eliya Ben Baruch - avatar