+ 1
The following question $i=1; do{echo"hello";}while(i<0); how does this code print hello once?
I think the right answr is none coz given that I=1 and I<0 is the condition (while loop) so it is false as 1!<0.please help me anyone..
7 Answers
+ 4
@NihalFarhan, the do...while loop will always execute the function one time before checking the while logic. So it always occurs, even if the first evaluation is false.
+ 1
@NIHAL In programming Language code is always tested from top to bottom. Hence, first the echo command will be executed and later the condition will be checked. This is the reason why we call this exit_control loop.
0
No, correct answer is " once " because it is already said--> echo "hello",so echo command wil be executed and you wil get hello once but with do and while, hello wil not anymore be executed because 0 is not greater then 1
0
the statement in do will execute once before it check in while operation
0
Because no matterwhatthe code always runs at least once, even if false
0
as name says, first do whatever the statement is then check the condition block.
0
when do...while loop runs for the first time, it doesn't check the condition bcs it always check the condition at the last of do... while loop. That's why the code inside the this loop will be expected at least once.