Question

. In your own words briefly explain in what way the while loop is similar to...

. In your own words briefly explain in what way the while loop is similar to the if statement

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The only similarity between a while loop and an if statement is that they both check the satisfaction of a condition before executing the statements inside them. Let's see an example.

int i = 0;

while( i < 5 ){

print( i );

i++;

}

if ( i > -1){

i = i + 1;

}

In the while loop, we are checking whether the value of i is less than 5 or not. If it is, we print i otherwise we break out of the while loop. Similarly, in the if statement we are checking if the value of i is greater than -1 or not. If it is, we increment i by 1 otherwise we ignore the statements inside the if condition.

A while loop is more similar to a for loop in its functioning. Both of them involve initializing the value of a variable, then checking a particular condition and finally updating the value of the variable after every iteration.

Let me know if you have any doubts in the comments. Please upvote if the answer helped you.

Add a comment
Know the answer?
Add Answer to:
. In your own words briefly explain in what way the while loop is similar to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT