Control Structures

 

Here is the code used in this lesson:

 


// CONTROL STRUCTURES

//1) SELECTION STRUCTURES

RuleContext selection {
	Rule rule {
		// IF STATEMENT
		String a = “hello”
		String b = “bye”

		If (a == b) { // false
			// code block to execute
		}

		If (a == b) { // true
			// code block to execute
		}
}
}

//2) ITERATION STRUCTURES

RuleContext iteration {
	Rule rule {
		// WHILE STATEMENT
		Integer a = 38
		Integer b = 0

		while (a > b) {
// code block to execute
b = b + 1	
		}
		
		// FOR STATEMENT
		Array arInt = [1, 2, 3, 4, 5]

		for x in arInt {
			broker.ui.showAlert(x.toString(), x.toString())
		}
}
}

> Next