What can we use instead of if in programs? I don't mean the switch case.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
What can we use instead of if in programs? I don't mean the switch case.
Explain what you want to do.
I read the title of your post and thought you were proposing a "what" keyword. That would be cool, but I suspect it violates some deep rules of logic.
But you're not proposing that, so I don't really know what you're asking.
boolean done = false; for(;<condition>&&!done;) { <whatever>; done = true; } for(;!done;) { <whatever else>; done = true; }
I don't want to use " if " or " switch ". Is anything else available in java for this functionality? For example, if I don't want to use "for" I can use "while".
Sorry for misunderstanding, my level in English...
There is a related but different construct: the ternary operator.
But nothing that's intended to replace the functionality of if. Is there anything in other languages?
I don't know if other languages have sth more but I'm trying to learn java and I'm wondering if there is something else instead of "if ". Thank you for your answer.
What statement you use depends on what the program logic requires. the if statement has a purpose and usage that is more natural that using a for or while with an extra boolean variable to end its looping.