Please enable JavaScript to use CodeHS

CodeHS Glossary


If Statement General

An if statement lets you ask a question to the program and only run code if the answer is true. This allows you to check something about the certain state of the world and perform an action based on the answer to your question. For example, if you want Karel to only put down a ball if there is not a ball present, you can say: if (noBallsPresent()) { putBall(); } This will ask the world if there is no ball at that spot, and if there isn't, it will put one. ---------- You can put any [condition][1] or [boolean][2] inside an if statement. ---------- Note: There is no such thing as an "if loop." It is just called an "if statement." [1]: http://codehs.com/glossary/term/6 [2]: http://codehs.com/glossary/term/8