Presentation is loading. Please wait.

Presentation is loading. Please wait.

If-Statements and If/Else Statements

Similar presentations


Presentation on theme: "If-Statements and If/Else Statements"— Presentation transcript:

1 If-Statements and If/Else Statements
Using Conditionals to make decisions

2 REVIEW OF LOOPS! What is the best way for Karel to move 10 times?
move(); move(); move(); move(); move(); move(); move(); move(); move(); move(); B. for (var i = 0; i < 10; i++) { move(); } C. move(10); D. move10();

3 What does this For loop mean?
for (var i = 0; i < 10; i++) { move(); } “Var i” refers to everything inside the curly brackets, so when it says “i <10; I++” it is actually saying that it will call “var i”, add one number to it, and then follow the loop again UNTIL it is equal to or greater than 10.

4

5 When to use If-Statements
If statements have a specific purpose, just like functions and loops. Statements help the computer prevent errors by calculating a decision based on the rules it has created. When would we use something called an “If/Else-Statement”?

6 If/Else Statements If/Else statements are used when you need the computer to make more complex responses to decisions, meaning that it is dealing with multiple true or false problems


Download ppt "If-Statements and If/Else Statements"

Similar presentations


Ads by Google