if-else in WLST
This is common decision making control in every programming language same in WLST. Python based program control much simple no braces required when you construct the if condition. There is no complex confusions for string comparisons and numeric value comparisons. As you know there is no semicolons for statements. The relational operators we have to use straight English words and, or, not.
if-elif-else in WLST : if-else ladder
Before you enter here you need to check this really required that gives optimizing your WLST script.
|if-elif-else in WLST Scripting|
Most of the WLST scripts that you develop for reuse with iterative process need to be in the looping structures for more time. If you write the script optimized way means you need to focus on few facts:
clean, faster, better
While loop can be used when you want to pass the iterations with numbers. We need to initialize the iteration variable and within the loop we need to increase or decrease that value to complete the loop. While loop will be entered into its block when the given expression is executed and resulted true.
Iterations in WLST ScriptsWe can see the major categories of WLST iterations control flows available such as 'for loop' and 'while loop'. Before iterating important Python function for automatic number list generation is given below.
The range() functionWhen you are using for-loop best trick to use with range built in Python function. It will take three different optional arguments and gives you different variety of values in the range of list as output.
- Until the given number
- From one particular value to another
- From one value to another with increment by value
Experimenting with range function to understand all its capabilities The range command always start from the 0 if you pass single argument that is considered as number of values you want as output.
wls:/offline> R=range(11) wls:/offline> R [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] wls:/offline> R=range(2,10,2) wls:/offline> R [2, 4, 6, 8] wls:/offline> R=range(2,10,3) wls:/offline> R [2, 5, 8]
While loop controlThis loop control works as same as in C programming style loop. The execution of while loop should not have any control on the variable that is used for iterate the loop. You need to initialize, check the termination condition and in the while loop block it should be iterated by increase or decrease as per program needs.
|WLST While loop - WLST for loop|
wls:/offline> while i<10: ...="" i="" jms0_server="" jms1_server="" jms2_server="" jms3_server="" jms4_server="" jms5_server="" jms6_server="" jms7_server="" jms8_server="" jms9_server="" jms="" pre="" print="" server="" str="">
The 'for loop' in WLSTEvery scripts developer favorite iterator control is for loop. Let us dive into some of the examples with it. The example of the 'for loop' in WLST is given belowwls:/offline> slist=range(1,11) wls:/offline> for i in slist: ... print 'managed'+str(i)+'_server' ... managed1_server managed2_server managed3_server managed4_server managed5_server managed6_server managed7_server managed8_server managed9_server managed10_server
While loop usage vs for loop1. Takes more time to executed 2. initialization, increase/decrease iterator variable 3. Easy to construct infinite loops with intervals For loop 1. Fastest loop 2. depends on range function to iterate on numbers 3. Flexible for including single lambda conditions Will update the following soon after sample executions completed. But these control flags works as in C language.10:>
The break statement in WLST, The continue statement in WLST, The pass statement in WLST