tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Java Scripting > BeanShell > For loop

For loop 

BeanShell is a small, free, embeddable Java source interpreter with object scripting language features, written in Java. BeanShell is a natural scripting language for Java. This requires the library bsh-2.0b4.jar to be in classpath. The following example shows simple for loop in beanshell script.

File Name  :  
/BEAN_SHELL001/config/forloop.bsh 
   
//Typed for loop
for (int i = ; i < ; i ++) {
  print("BTC");
}

//UnTyped for loop
for (i = ; i < ; i ++) {
  print(name);
}
   

File Name  :  
com/bethecoder/tutorials/bean_shell/ForLoopTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.bean_shell;

import java.io.InputStreamReader;
import bsh.EvalError;
import bsh.Interpreter;

public class ForLoopTest {

  /**
   @param args
   @throws EvalError 
   */
  public static void main(String[] argsthrows EvalError {
    Interpreter interpreter = new Interpreter();  
    interpreter.set("name""Sriram");            

    InputStreamReader reader = new InputStreamReader(
        ForLoopTest.class.getClassLoader()
        .getResourceAsStream("forloop.bsh"));
    
    interpreter.eval(reader);
  }

}
   

It gives the following output,
BTC
BTC
BTC
BTC
Sriram
Sriram
Sriram
Sriram


                    Print

   



Books Recommendation

 
 
bl  br