what does 10 means in while(10) and why it excuate infinity times like while (1) iz 10 also means true same like 1 ?????
why while(10) excuate body infinity times ???
Collapse
X
-
Tags: None
-
while(10) is the same as while(1) or any other symbolic constant.
It means that the loop runs forever.
You usually see this in a menu driver:
Code:int choice; while(1) { choice = getChoice(); switch (choice) { case 1: ..this is menu choice 1... break; case 2: .. this is menu choice 2.. break; default: ...this is a bad choice.. } } }
-
yes in C programming loop has two possibilities
1)true -i.e. any non-zero values are considered as true
2)false -i.e. only value zero is used to end the loop
Note:Its nice practice to use while(10)
but you must take care that you explicitly mention a break statement to avoid infinte loopsComment
-
The break statement I used was for the switch inside the loop. The loop is intended to be infinite so process always returns back to the menu.
There is nothing wrong in using infinite loops.Comment
-
-
Comment