+ 2
Int i=0,n=10; while (i<n) i++; find the loop
47 Antworten
+ 6
Thank you!🥰
+ 3
Subhasmita Dash welcome 👍
+ 3
Can you add your understandings or your difficulty in your 2nd code Subhasmita Dash?
ok. let initially x = 0 , next
x >= 0 true so adds x += 5 => x = 5
x >= 5 true so adds x += 2 => x = 7
+ 2
Subhasmita Dash i ki value abhi starting main 0 hai jab aapne loop chalaya hai
while(i<n)
iska matlab hai ki 0<10 kyuki n ki value 10 hai abhi uske baad increment ho rha hai increment ka matlab hota hai +1 kar dena like that :- i++, iska matlab i main +1 kar dena aise 0+1=1 ab i ki value 1 hai, ab phirse while loop main jayenge aur condition check karega 1<10 kyonki i ki value ab 1 hai aur n ki value 10 hi hai toh ab phirse 1 kam hai 10 se toh condition true hai now, phirse increment karega like that:- 1+1=2 ab i ki value 2 hai aur phirse while loop main check karenga aise aise chalta jayega loop tab tak jab tak i ki value 10 na ho jaye jaise hi i ki value 10 hogi like that:-
10<10 iska matlab condition false hui ab loop exit ho jayega yani stop ho jayega, I hope now you understand.
+ 2
Subhasmita Dash haan, starting main i ki value 0 hogi kyoki aapne i ki value 0 le rakhi hai aur jab loop main aayega tab last main i ki value 10 ho jayegi kyonki n ki value bhi 10 hai toh last main hoga 10<10 aur while loop stop ho jayega aur last main i ki value 10 hongi.
+ 2
#include <stdio.h>
int main() {
int i=0;
int n=10;
while(i<n)
{
printf("%d\n",i);
i++;
}
return 0;
}
+ 1
Please share the code
+ 1
Subhasmita Dash
// intialize i variable and n variable
i=0;
n=10;
// Now you use while loop
while(i<n)
// that means 0<10 it's true
i++;
// Now you increment the i by 1
// Like that:- 0+1= 1
//And the while loop run until the i value becomes 10 when i value is 11 that means the condition is false and the loop will exit
// Hope you understand my explanation
+ 1
Yes so i value is 10
Right?
+ 1
Yes
Thank you dear!
+ 1
What would be the value of x after the following code segment completes execution?
Int x =0;
If (x>=0)
x+=5;
If (x>=5)
x+=2;
+ 1
While loop is working till i=9, and hence we get i=10.
+ 1
int i=0, n=10;
while(i<n)
{
Print i;
i++;
}
So this while loop will run 9 times upto i value will become 9, so it's print a numbers 0 to 9 and when the value of i=10 then condition is not satisfied, So the loop will not run on that time.
Loops are used to run a specific line of code for a certain times without writing that line of codes repeatedly.
And here we are using a while loop it is a indefinite loop.
+ 1
Subhasmita Dash Welcome
0
Explain the process
0
What would be the value of i after program segment comples execution? Int i=0,n=10; while (i<n) i++;
0
But how dear
0
i value 10 me execution complete hota hai na
So value of i will be 10 ?
0
Sorry