Please enable JavaScript to use CodeHS

CodeHS Glossary


If Else Statement General

Control structure that lets us run either one section of code or another depending on a test. In Karel, we can write out an if else statement like this: ``` if(frontIsClear()) { // Code to run if the front is clear } else { // Code to run otherwise } ``` If the condition inside the if statement is true, the block of code inside the if statement will run. If the condition is false, the block of code inside the else statement will run. Only one section of code will run, not both. It's one or the other, depending on whether the condition in the if statement is true or false.