When you get down to it, any boolean expression results in a value of zero = fal
ID: 3636148 • Letter: W
Question
When you get down to it, any boolean expression results in a value of zero = false or not zero = true.Does this mean that
if (1) {
//do something
}
the line body of this loop will always be entered?
what about
while(1) {
//loop body
}
Why would you want to do that?
A common approach is to use meaningful names and assign them zero or non zero values
int count=0;
while(count) {
//only get here when count is not 0
}
or
int count=0
do {
if (some event is true) {
count++;
}
else {
count = 0;
}
while (count);
your feedback?
Explanation / Answer
1 is a non-zero value which means true
For if(1){} , its body is always executed
For while(1){},it is looped continuously
If a break statement is present in the loop for a condition,then the loop gets stopped when the break statement is reached
But if no break statement is present,there will be infinite loop
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.