Presentation is loading. Please wait.

Presentation is loading. Please wait.

Selections and Loops By Sarah, Melody, Teresa.

Similar presentations


Presentation on theme: "Selections and Loops By Sarah, Melody, Teresa."— Presentation transcript:

1 Selections and Loops By Sarah, Melody, Teresa

2 If Statements What does an If statement do?
An if statement controls if a certain section of code will execute if it's true. If the statements conditions are false then the code within the section will not be executed. How to use If statements… The format of an if statement is... If ( conditions ) { Code that will execute } UwU If ( conditions ) { Code that will execute }

3 Else-if & Else Statements
Needs an if statement to work Can have as many as you want Gives user a choice Must start and end with a curly bracket example: else if(condition) { statements; } Else Last statement Will execute if nothing else does Isn’t necessary but can be included Must start and end with a curly bracket example : else { statements; }

4 Switch Statements Like an if else if statement except the condition will always evaluate to an integer Instead of “elseif”, you would use “case (integer): ” After statement(s) have been executed, there must be a “break” statement The break will stop the checking of other cases There may be a default case to represent else switch (num) { case 0: statements; break; default: }

5 For Loops What is a for loop?
A for loop is a counted loop that will repeat a section of code a set number of times. Once the loop reaches the number of times it is set to loop then it will stop. What does a for loop look like? for(int i = num; i < num; i + or -) { Code that is repeated } Owo

6 While loops A pre-conditional loop
Will only execute if condition is true Can run an infinite amount of times Good for when you’re unsure of the amount of times you need a loop If the statement isn’t true the loop may never execute Example: While (condition) { Statements; }

7 Do-while loops A post-conditional loop
Instead of checking for the condition first, it’ll check after the execution the code inside the loop will always at least execute/loop once Will keep looping if condition is true, otherwise if false it won’t do { Statements; } while (condition);

8 “Mr. Mooney, why isn’t my code working?”
Thanks for watching owo “Mr. Mooney, why isn’t my code working?” - From an expert


Download ppt "Selections and Loops By Sarah, Melody, Teresa."

Similar presentations


Ads by Google