a4fdc29bace64fb058e1dcf6d7d46be1.ppt
- Количество слайдов: 21
Eastern Mediterranean University School of Computing and Technology Department of Information Technology ITEC 229 Client-Side Internet and Web Programming Conditional Statements & Loops in Java. Script CHAPTER 10 LOGO
CONTENT 10. 1 Conditional Statements § if. . Statement § if. . else if Statement § switch case Statement 10. 2 Loops § For Loop § While Loop § Do. . While Loop 2 http: //sct. emu. edu. tr/it/itec 229
10. 1 Conditional Statements v Conditional statements are used to perform different actions based on different conditions. v Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this. 3 http: //sct. emu. edu. tr/it/itec 229
10. 1 Conditional Statements In Java. Script we have the following conditional statements: v if statement - use this statement to execute some code only if a specified condition is true v if. . . else statement - use this statement to execute some code if the condition is true and another code if the condition is false v if. . . else if. . else statement - use this statement to select one of many blocks of code to be executed v switch statement - use this statement to select one of many blocks of code to be executed 4 http: //sct. emu. edu. tr/it/itec 229
10. 1 Conditional Statements if statement: v Use the if statement to execute some code only if a specified condition is true. Syntax: if (condition) { code to be executed if condition is true } 5 v Note that if is written in lowercase letters. Using uppercase letters (IF) will generate a Java. Script error! v Notice that there is no. . else. . in this syntax. You tell the browser to execute some code only if the specified condition is true. http: //sct. emu. edu. tr/it/itec 229
var total=0; var even=0;" src="https://present5.com/presentation/a4fdc29bace64fb058e1dcf6d7d46be1/image-6.jpg" alt="10. 1 Conditional Statements if statement: Example:
10. 1 Conditional Statements if. . else statement: Syntax: if (expression) { statement(s) to be executed if expression is true } else { statement(s) to be executed if expression is false } 7 http: //sct. emu. edu. tr/it/itec 229
var total =" src="https://present5.com/presentation/a4fdc29bace64fb058e1dcf6d7d46be1/image-8.jpg" alt="10. 1 Conditional Statements if. . else statement: Example: 8 http: //sct. emu. edu. tr/it/itec 229
10. 1 Conditional Statements if. . else if statement: Syntax: if (expression 1) { statement(s) to be executed if expression 1 is true } else if (expression 2) { statement(s) to be executed if expression 2 is true } else if (expression 3) { statement(s) to be executed if expression 3 is true } else { statement(s) to be executed if no expression is true } 9 http: //sct. emu. edu. tr/it/itec 229
var age" src="https://present5.com/presentation/a4fdc29bace64fb058e1dcf6d7d46be1/image-10.jpg" alt="10. 1 Conditional Statements if. . else if statement: Example: 10 http: //sct. emu. edu. tr/it/itec 229
10. 1 Conditional Statements switch case statement: Syntax: switch (expression) { case condition 1: statement(s) break; case condition 2: statement(s) break; . . . case condition n: statement(s) break; default: statement(s) } 11 http: //sct. emu. edu. tr/it/itec 229
var flower=prompt("Which flower" src="https://present5.com/presentation/a4fdc29bace64fb058e1dcf6d7d46be1/image-12.jpg" alt="10. 1 Conditional Statements switch case statement: Example:
10. 2 Loops For Loop: Example Output: 16 http: //sct. emu. edu. tr/it/itec 229
10. 2 Loops The while Loop: v loops through a block of code as long as a specified condition is true. Syntax: while (condition) { statement(s) to be executed if expression is true } 17 http: //sct. emu. edu. tr/it/itec 229
var total=0; var i=0; Output:" src="https://present5.com/presentation/a4fdc29bace64fb058e1dcf6d7d46be1/image-18.jpg" alt="10. 2 Loops The while Loop: Example: 18 http: //sct. emu. edu. tr/it/itec 229
10. 2 Loops The do. . while Loop: v similar to the while loop except that the condition check happens at the end of the loop. v this means that the loop will always be executed at least once, even if the condition is false. Syntax: do { statement(s) to be executed; } while (condition); 19 http: //sct. emu. edu. tr/it/itec 229
Output: var num" src="https://present5.com/presentation/a4fdc29bace64fb058e1dcf6d7d46be1/image-20.jpg" alt="10. 2 Loops The do. . while Loop: Example: 20 http: //sct. emu. edu. tr/it/itec 229
Conditional Statements & Loops in Java. Script END of CHAPTER 10 LOGO http: //sct. emu. edu. tr/it/itec 229


