- Jython - Dialogs
- Jython - Menus
- Jython - Event Handling
- Jython - Layout Management
- Jython - Using the Swing GUI library
- Jython - JDBC
- Jython - Servlets
- Jython - NetBeans Plugin & Project
- Jython - A Project in Eclipse
- Jython - Eclipse Plugin
- Jython - Java Application
- Jython - Package
- Jython - Modules
- Jython - Functions
- Jython - Loops
- Jython - Decision Control
- Jython - Using Java Collection Types
- Jython - Variables and Data Types
- Jython - Importing Java Libraries
- Jython - Installation
- Jython - Overview
- Jython - Home
Jython Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Jython - Decision Control
Decision making structures have one or more conditions to be evaluated or tested by the program, along with a statement or statements that are to be executed, if the condition is determined to be true, and optionally, other statements to be executed, if the condition is determined to be false.
The following illustration shows the general form of a typical decision making structure found in most of the programming languages −
Jython does not use curly brackets to indicate blocks of statements to be executed when the condition is true or false (as is the case in Java). Instead, uniform indent (white space from left margin) is used to form block of statements. Such a uniformly indented block makes the conditional code to be executed when a condition given in ‘if’ statement is true.
A similar block may be present after an optional ‘else’ statement. Jython also provides the epf statement using which successive conditions can be tested. Here, the else clause will appear last and will be executed only when all the preceding conditions fail. The general syntax of using if..epf..else is as follows.
if expression1: statement(s) epf expression2: statement(s) epf expression3: statement(s) else: statement(s)
In the following example, if ..epf ..else construct is used to calculate discount on different values of amount input by user.
discount = 0 amount = input("enter Amount") if amount>1000: discount = amount*0.10 epf amount>500: discount = amount*0.05 else: discount = 0 print Discount = ,discount print Net amount = ,amount-discount
The output of above code will be as shown below.
enter Amount1500 Discount = 150.0 Net amount = 1350.0 enter Amount600 Discount = 30.0 Net amount = 570.0 enter Amount200 Discount = 0 Net amount = 200Advertisements