Загрузка...

Nested if & Multiple selection control structures - Java programming tutorial for beginners

Nested if & Multiple selection control structures - Java programming tutorial for beginners This video is the continuation of the previous videos I made on if statements and if-else statements In these videos, we learned how to implement one-way and two-way selection control structures Now, in this video, I will show you how to use Nested if statements and also how to implement a multiple-way selection control structure The Nested if statement and Multiple-way selection control structure are useful when you want your program to choose between multiple action statements. So, it allows the user to decide among multiple options. The Multiple-way selection control structure can take two forms The first form is the classical one, involving an if statement that has multiple selection paths, if (score greater than 90) System.out.println("The grade is A"); else if (score greater than 80) System.out.println("The grade is B"); else if (score greater than 70) System.out.println("The grade is C"); else if (score greater than 60) System.out.println("The grade is D"); else System.out.println("The grade is F"); So, these if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the action statement associated with that if, is executed, and the rest of the action statements are skipped. If none of the conditions is true, then the final else statement will be executed The second form of a multiple-way selection control structure is what we commonly call the Nested if A nested if is an if statement that is the target of another if or else statement. In other words a Nested if statement means that you have got an if statement inside another if statement. So, Java allows us to nest if statements within other if statements. That is to say that, we can place an if statement inside another if statement Here is how a nested if statement looks like if (temperature greater than 50) if (temperature greater than 80) System.out.println("Good day for swimming."); else System.out.println("Good day for golfing."); else System.out.println("Good day to play tennis."); So, guys, that’s it concerning the multiple-way selection control structure and nested if statements Thanks for viewing, I hope this video was informative, and please do not forget to like and SUBSCRIBE to this channel. Let’s meet in the next one #codingriver #java #programming

Видео Nested if & Multiple selection control structures - Java programming tutorial for beginners автора Техно-Хакер
Страницу в закладки Мои закладки
Все заметки Новая заметка Страницу в заметки